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