Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Join same table twice ( SQL ) 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
I am having problems with my SQL I am basicly trying to get two "thread" names from the same table (thread) here is what i have...


Code:
sql= "SELECT "_
& "post.pid,"_
& "post.ptid,"_
& "post.ptid2,"_
& "post.puid,"_
& "post.psubject,"_
& "post.ptype,"_
& "post.preplycount,"_
& "post.ptime,"_
& "post.psticky,"_
& "post.ptimereply,"_
& "user.uid,"_
& "user.uname,"_
& "th.tid,"_
& "th.tname as ThreadName1,"_
& "th2.tid,"_
& "th2.tname as ThreadName2,"_
& " FROM forumpost as post, users as user, thread as th, thread as th2 LEFT join on user.uid=post.puid WHERE post.ptype=0 AND th.tid=post.ptid AND th2.tid=post.ptid2 Order by DESC,post.pid DESC Limit " & sLimitPart
 
nevermind... i got it!

For anyone who cares...

Code:
sql= "SELECT "_
& "post.pid,"_
& "post.ptid,"_
& "post.ptid2,"_
& "post.puid,"_
& "post.psubject,"_
& "post.ptype,"_
& "post.preplycount,"_
& "post.ptime,"_
& "post.psticky,"_
& "post.ptimereply,"_
& "user.uid,"_
& "user.uname,"_
& "th.tid,"_
& "th.tname as ThreadName1,"_
& "th2.tid,"_
& "th2.tname as ThreadName2"_
& " FROM forumpost as post, users as user INNER JOIN thread th ON th.tid=post.ptid INNER JOIN thread th2 on th2.tid=post.ptid2 WHERE post.ptype=0 AND user.uid=post.puid Order by post.pid DESC Limit " & sLimitPart

Site San Diego www.sitesd.com

 
just a tip regarding this code --
Code:
FROM forumpost as post, users as user 
INNER JOIN thread th ON th.tid=post.ptid
as you can see, this mixes the "table list" and JOIN syntaxes

my advice: change this now to use JOIN syntax only

mixing them can (and will, in this particular instance) give you a syntax error in version 5

see
:)

r937.com | rudy.ca
 
thanks for the tip! I would have never known this until MySQL was upgraded ha:)

Site San Diego www.sitesd.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top