Jump to content

JOIN + IF clause


sader

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/191416-join-if-clause/#findComment-1009128
Share on other sites

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|[email protected]|100   

2 |Lacy|[email protected]|16   

3 |Cody|[email protected]|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

[email protected]

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

Link to comment
https://forums.phpfreaks.com/topic/191416-join-if-clause/#findComment-1009165
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.