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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

join w/ subquery

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
What i am going to do here is Select all replys by a user, but don't display posts they "started", the first SQL was for ones they started.

Main post is signified by f.ptype=0
A reply is f.ptype=1 a reply will also have the main post's id in the column f.preplyid

Its erroring on the subquery
-----------------
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT fp.pid, fp.puid, fp.ptype FROM forumpost as fp WHERE fp.
--------------------------


Code:
SELECT 
f.pid, 
f.ptid, 
f.ptid2, 
f.puid, 
f.psubject, 
f.ptype, 
f.preplyid, 
f.ptime, 
t1.tid, 
t1.tname 
tname1, 
t2.tid, 
t2.tname 
tname2 
FROM 
forumpost as f, 
thread as t1, 
thread as t2 
WHERE t1.tid = f.ptid AND t2.tid = f.ptid2 
AND 
f.puid =2 
AND 
f.ptype=1 
AND f.puid NOT IN 
(SELECT fp.pid, fp.puid, fp.ptype FROM forumpost as fp WHERE fp.ptype=0 AND fp.puid=f.preplyid) 

ORDER by f.ptime desc LIMIT 7
 
What MySQL version are you using? Subqueries like that are only available in v. 4.1 or later.
 
Oh no! that would make since... just my luck i have 4.0.24 hmm what other method do you suggest?

 
Ok i installed 4.1.21 and its working, however its still selecting posts replies that were started by the same person


Code:
SELECT f.pid, f.ptid, f.ptid2, f.puid, f.psubject, f.ptype, f.preplyid, f.ptime, t1.tid, t1.tname tname1, t2.tid, t2.tname tname2 FROM forumpost as f, thread as t1, thread as t2 WHERE t1.tid = f.ptid AND t2.tid = f.ptid2 AND f.puid =2 AND f.ptype=1 AND f.puid NOT IN (SELECT fp.puid FROM forumpost as fp WHERE fp.ptype=0 AND fp.puid=f.preplyid) ORDER by f.ptime desc LIMIT 7

Do you got a million? www.gotamillion.com/?r=T

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top