Log in

View Full Version : user.userid explained


TECK
04-04-2002, 01:20 AM
can you help me understand the mechanism of this query?$posts=$DB_site->query("
SELECT
post.*,post.username AS postusername
FROM post
LEFT JOIN user ON user.userid=post.userid
LEFT JOIN userfield ON userfield.userid=user.userid
WHERE $postids
ORDER BY dateline $postorder
");why post.*,post.username and not only * ?
why is it present the user. part?
what is the difference between user.userid and post.userid? why i see all the time this kind of code structure (user.userid) in vB?

Zzed
04-04-2002, 04:43 AM
It seems reduntant. There are no fields that are being selected from user.

Admin
04-04-2002, 05:19 AM
Actually Zzed I think nakkid posted a shortened version of the showthread.php query.

tblName.fldName is called qualification. It's used when you select data from multiple tables, although it's only required if you have the same field in both tables (specifying the table name so it knows from which table to select the field). If you don't do this you will get an ambiguousness error.

Zzed
04-04-2002, 06:12 AM
Given what nakkid posted it seemed redundant. But within the context of showthread.php it makes perfect sense. How else would you populate the user information without selecting from user.* in order to show the posts? ;)

Admin
04-04-2002, 06:19 AM
Oh, nakkid, re why post.username AS postusername and not just post.*:
For guests we want to show what they entered in the form, so choosing user.username would override post.username, and since user.username is empty (not registered) we won't have a username at all.

TECK
04-04-2002, 07:41 AM
firefly, you guessed right about the shortened version.
your explanation answer my questions. thank you.