Jump to content

complex select statement


ellegua220

Recommended Posts

can someone break this statement down?  what  are the u and pu and p?  is that shorthand for user, parent_user and parent?  if so, what if you had 2 tables with the same first letter? also can you break down the join for me with an example data set?

> $query="SELECT * FROM user u LEFT JOIN parent_user pu ON pu.userid =

> u.userid LEFT JOIN parent p ON p.parent_id = pu.parent_id WHERE

> u.userid = $userid";

>

 

Link to comment
Share on other sites

Yes, those are table aliases and they are set in the query to be shorter, they can be anything you want not just the first letter.  You could do this:

 

SELECT * FROM user t1
LEFT JOIN parent_user t2 ON t2.userid = t1.userid
LEFT JOIN parent t3 ON t3.parent_id = t2.parent_id
WHERE t1.userid = $userid

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.