rootpanthera
rootpanthera

Reputation: 2771

How to write this particular sql statement

I currently have a SQL query like this:

SELECT TOP 10 column_name 
FROM table_name 
ORDER BY voteColumn DESC

"voteColumn" is integer based. People from my app hit +1 or -1 and feedback is calculated based on current value in "voteColumn".

But there is a problem because there are records which don't have a feedback yet, and their default value is "0". I don't want to show those records. So basically I'm asking is , how to convert this statement into a SQL statement if possible:

SELECT TOP 10 column_name 
FROM table_name 
ORDER BY voteColumn Desc -> but not return any column_name if value is "0" or return only those who value is above "0".

Any help appriciated.

Upvotes: 0

Views: 41

Answers (3)

sqlab
sqlab

Reputation: 6436

  SELECT TOP 10 column_name FROM table_name   
  WHERE voteColumn > 0   
  ORDER BY voteColumn Desc

Upvotes: 1

CodingQuant
CodingQuant

Reputation: 320

If you want to output results where the voteColumn value is greater than 0, then you just need a WHERE statement.

SELECT TOP 10 column_name FROM table_name 
WHERE voteColumn > 0
ORDER BY voteColumn Desc

Upvotes: 0

juergen d
juergen d

Reputation: 204766

SELECT TOP 10 column_name 
FROM table_name 
WHERE voteColumn <> 0
ORDER BY voteColumn Desc

Upvotes: 3

Related Questions