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

How do I query multiple fields?

Status
Not open for further replies.

Chelsea7

Programmer
Aug 25, 2008
69
US
Good day,

I created a survey with several questions. I would like to query the highest number of responses from the 3 questions and display only the one with the highest. This is what I have in MYSQL;

Fields: Total:
RESPONSE 1 8
RESPONSE 2 6
RESPONSE 3 10

The fields have 'Y' for answers. So I'm counting the number of 'Y''s for each field.

Display;

Response 3

Is there a simple way to query this in php?

Thank you

 
why is this a php question?

in mysql surely you would just do this
Code:
select `field` from tablename order by sum(case `answer` when 'Y' then 1 else 0 end) DESC limit 1
where 'field' is the column name for the 'Response 1' column and 'answer' is the column name for the Y/N

it would might be even easier if you had designed your table better. For example instead of Y/N why not 1/0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top