Skip to content
Advertisement

Compare two values in a row

Ergebnis:

enter image description here

Now i need only the first row “first_name” = “Eins” because “yes” equals “no”. How can i make this where statemant? WHERE yes = no … doesn’t work.

Thanks for any help

Advertisement

Answer

I would phrase the query as:

Rationale:

  • the conditional expressions in the sum() can be simplified

  • you can use a having clause for filtering; MySQL also supports reusing aliases defined in the select clause in the having clause, so you could spell this: having yes = no – but I prefer repeating the conditional expression, since this is standard SQL

  • the left join on audition_card_values followed by a where ... is not null on the joining column can be rewritten as a simple inner join

  • I fixed your group by clause; every non-aggregated column in the select clause must appear in the group by clause

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement