954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to select rows that has only one condition

This is how my license table look like.. i want to select only row that has atleast one "1".
which means i don't want to select any row that has full of zeros..

Attachments ggg.PNG 9.79KB
fire eaters
Newbie Poster
16 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

Use a calculated column that sums all your 0/1 columns. Then you can just add WHERE summed > 0

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
Use a calculated column that sums all your 0/1 columns. Then you can just add WHERE summed > 0

you mean a calculated colum as an alias right. give me an idea to summ all 0/1..

fire eaters
Newbie Poster
16 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

SUM(column1, column2, ...) or just column1 + column2 + ...

pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
SUM(column1, column2, ...) or just column1 + column2 + ...
SELECT 
sum(F1)+sum(F2)+sum(F3)+sum(F4)+sum(F5)+sum(F6)+sum(F7)+sum(F8)+
sum(A)+sum(A1)+sum(B)+sum(B1)+sum(B2)+sum(C)+sum(C1)+sum(C2)+sum(V1)
as total
FROM `licence` 
WHERE total> 0


the error says unknown column total. my idea is to select rows that atleast have one "1"

fire eaters
Newbie Poster
16 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
 
SELECT *
FROM `licence` 
WHERE F1+F2+F3+F4+F5+F6+F7+F8+A+A1+B+B1+B2+C+C1+C2+V1 > 0
pritaeas
Posting Expert
Moderator
5,484 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You