0

With one select command, display all cats with male sex and dogs whith female sex

i'have tried select * from pet where species='cat' && sex='m' | species='dog' && sex='f';

1

1 Answer 1

1

You connect boolean expressions in SQL using AND and OR, not strange operators lifted from C:

where (species = 'cat' and sex = 'm') or
      (species = 'dog' and sex = 'f');

MySQL also supports IN with tuples:

where (species, sex) in ( ('cat', 'm'), ('dog', 'f') );

And just to clarify: MySQL does understand && and || as real boolean operators. I strongly discourage anyone from using this (mostly my general preference for standards when they are equivalent). However, & and | are bitwise operators, so they may not do what you expect in a boolean context.

Sign up to request clarification or add additional context in comments.

1 Comment

"strange operators lifted from C:" I loved that. hahaha!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.