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!

DISTINCT still showing duplicate records 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH

Why won't distinct work? The sql IS selecting correctly but its showling records with the same f.preplyid

Code:
SELECT DISTINCT (f.preplyid), f.pid, f.ptid, f.ptid2, f.puid, f.psubject, f.ptype, 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.pid=f.preplyid) ORDER by f.ptime desc LIMIT 7
 
with LIMIT 7, the number of rows is 7

perhaps what you want is the number of rows it would've returned if there were no LIMIT?

please see the FOUND_ROWS function in the manual

r937.com | rudy.ca
 
The problem with that is i have to know before i do the select... because i am doing a "posts participated in" count
 
The number of records returned for that SQL statement... i forgot to remove the limit in the thing i copied... but it wasn't in the one i tested...


Code:
select distinct
       main.pid
     , main.puid
     , main.psubject
     , main.ptime
     , main.ptid
     , t1.tname tname1
     , main.ptid2
     , t2.tname tname2
  from forumpost as reply
inner
  join forumpost as main
    on main.pid = reply.preplyid
   and main.ptype = 0
   and main.puid <> reply.puid
inner
  join thread as t1
    on t1.tid = main.ptid
inner
  join thread as t2
    on t2.tid = main.ptid2
 where reply.puid = 2
   and reply.ptype = 1
order
    by main.ptime desc
 
you want to know the number of rows returned by that query?

instead of, or in addition to the results of that query?

r937.com | rudy.ca
 
Yes i only want to know the number of rows that would be returned by that query i don't want to run the select itself just grab the number of rows that "would be" returned if it were ran...

thanks


Army : Combat Engineer : 21B

 
well, unfortunately you're going to have to "sort of" run it in order to get that count

Code:
select count(*) as would_have_returned
  from (
     [i]put entire query here[/i]
       ) as thequery

r937.com | rudy.ca
 
so are you telling me thats going to be inafficient? Because we are talking about Replies by a user... which could be in the 1000s. A lot of times I keep track of the numbers as it occurs, ie if someone posts something then update their post count etc... but it will be a pain if i have to delete posts etc etc... then I have to update x users... [thumbsdown]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top