Jump to content

Help with Left Join


MDanz

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

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

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.