Author Topic: JOIN + IF clause  (Read 97 times)

0 Members and 1 Guest are viewing this topic.

Offline saderTopic starter

  • Enthusiast
    • View Profile
JOIN + IF clause
« on: February 08, 2010, 05:09:20 PM »
Hi
I dont't understand joins very well but in this case I'm  confused even more...
I have three tables user, anonym, post

"Post"
id

Offline Maq

  • Freak!
    • View Profile
Re: JOIN + IF clause
« Reply #1 on: February 08, 2010, 05:16:12 PM »
Hi
I dont't understand joins very well but in this case I'm  confused even more...
I have three tables user, anonym, post

"Post"
id


I assume you didn't finish editing your post, until then it's impossible for us to help.  And if you did finish editing, than it's still impossible.
ini_set ("display_errors""1"); 
error_reporting(E_ALL);

Quality Scripts

Offline saderTopic starter

  • Enthusiast
    • View Profile
Re: JOIN + IF clause
« Reply #2 on: February 08, 2010, 06:11:14 PM »
continue...

Hi
I don't understand joins very well but in this case I'm  confused even more...
I have three tables: user, anonym, post

Table: user
id|name|email |points
1 |Adam|A@A.xx|100   
2 |Lacy|L@L.xx|16     
3 |Cody|C@C.xx|1720 

Table: anonym
id|name|
1 |Rose

Table: post
id|text|author_type|author_id
1 |aaaa|R          |1       
2 |bbbb|R          |3       
3 |cccc|A          |1       

Now I want to retrive data about post on specific id and data(which sometimes is stored in table "user" and sometimes in table 'anonym") about author of the post.

Let's take post with ID=3, query should return
post.id=3
post.text=cccc
post.author_type=A (A stands for anonym)
post.author_id=1
anonym.id=1
anonym.name=Rose

with ID=2

post.id=2
post.text=bbbb
post.author_type=R (R stands for registered user)
post.author_id=1
user.id=1
user.name=Cody
user.email=C@C.xx
user.points=1720

I tried various  queries which I could come across the last one look'd something like this:
SELECT * FROM post,user,anonym WHERE post.id=1 AND IF(post.author_type='R', SELECT * FROM user ..., SELECT * FROM anonym...)
but of course it failed since even syntax is incorrect

PHP Freaks Forums

« on: »

Tired of these ads? Purchase a supporter subscription to get rid of them.