The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
INNER JOIN query
Hi folks
Apologies in advance if this has been covered - I couldn't find the answer having done a bit of searching... I run vBadvanced and I want to produce a thank you box on the front page which shows the latest 10 positive reputation comments. The idea is to promote the reputation system and give people added incentive to give and receive rep points The information I want is in the reputation and user table. I want to get the following fields: reputation.postid reputation.userid reputation.whoadded reputation.reason user.username I've got this working with the following query: Code:
SELECT reputation.postid, reputation.userid, reputation.whoadded, reputation.reason, user.username FROM reputation INNER JOIN user ON reputation.userid=user.userid WHERE reputation.reputation >= 1 AND reputation.reason <> '' ORDER BY reputation.dateline DESC LIMIT 10; I'd be very grateful of any advice. I'm not feeling well today, and my brain hurts Thanks in advance... |
#2
|
|||
|
|||
Quote:
[SQL]INNER JOIN user userwho ON userwho.userid = reputation.whoadded[/SQL] And in your select, you'd reference it by userwho.username |
#3
|
||||
|
||||
It's good practice to use 'AS' (INNER JOIN user AS userwho .....).
|
#4
|
|||
|
|||
It may make it slightly more readable if that is the format you are used to using, but I find it to be superfluous and I usually omit it.
|
#5
|
||||
|
||||
Ok folks - thanks for that. I'll give it a go and report back
Thank you --------------- Added at 12:12 --------------- Thanks chaps - that gave me what I needed. The resultant query looks like this: Code:
SELECT reputation.postid, reputation.userid, reputation.whoadded, reputation.reason, user.username, userwho.username AS usernamefrom FROM reputation INNER JOIN (user INNER JOIN user AS userwho ON reputation.userid=user.userid) ON reputation.whoadded=userwho.userid WHERE reputation.reputation >= 1 AND reputation.reason <> '' ORDER BY reputation.dateline DESC LIMIT 10; |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|