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
https://forums.phpfreaks.com/topic/230343-complex-select-statement/
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

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.