Jump to content

Recommended Posts

I'm doing a left join query for the table below and it is not getting the correct results.  It should return the results peter, john and david  because they have the same sid and the wildcard is peter.

 

Instead it is returning carl, peter, john and david.  What do i have to change to correct this?

 

SELECT child.* FROM mytable child LEFT JOIN mytable parent on parent.sid=child.sid WHERE parent.name LIKE '%peter%' ORDER BY child.id ASC

 

idsidnameparent

0nullmike[/td]

[td]1

0rickmike

21carlrick

31peterrick

41johnrick

51davidrick

Link to comment
https://forums.phpfreaks.com/topic/246079-help-with-left-join/
Share on other sites

i tried that and now it is removing peter from results.  So the results are carl, john and david.

 

SELECT child.* FROM mytable child LEFT JOIN mytable parent on parent.sid=child.sid WHERE parent.name LIKE '%peter%' AND parent.name != child.name ORDER BY child.id ASC

Link to comment
https://forums.phpfreaks.com/topic/246079-help-with-left-join/#findComment-1263784
Share on other sites

Opps, I misread your problem to be that you didn't want the selected name to be included.

 

Is the data you posted correct? Carl has the same sid as the others. There's nothing in what you posted that would exclude carl form the result set.

Link to comment
https://forums.phpfreaks.com/topic/246079-help-with-left-join/#findComment-1263788
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.