sader Posted February 8, 2010 Share Posted February 8, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/191416-join-if-clause/ Share on other sites More sharing options...
Maq Posted February 8, 2010 Share Posted February 8, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/191416-join-if-clause/#findComment-1009128 Share on other sites More sharing options...
sader Posted February 8, 2010 Author Share Posted February 8, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/191416-join-if-clause/#findComment-1009165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.