Jump to content

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|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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.