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

show only greater than 0 on a count statement 1

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
I have this SQL :

Code:
Select DISTINCT th.tid, th.tname, th.tmain, th.tcolor, (SELECT COUNT(star.stid) FROM userstars as star WHERE star.stid=th.tid AND sonuid=1) as starcount FROM thread th WHERE th.tmain=1

I need to show only records that return a starcount of > 0 but when try to add star count to either the count or the where section of the SQL i get a column could not be found... how can i do this?

Regards,
Jason

Jason

[red]Army[/red] : [white]Combat Engineer[/white] : [blue]21B[/blue]

 
Code:
SELECT * FROM (
SELECT th.tid
     , th.tname
     , th.tmain
     , th.tcolor
     , (SELECT COUNT(star.stid) 
          FROM userstars as star 
         WHERE star.stid=th.tid AND sonuid=1) as starcount 
  FROM thread th 
 WHERE th.tmain=1
) AS t
WHERE t.starcount > 0
notice i removed your DISTINCT, which was unnecessary

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top