Skip to content
Advertisement

how to select multiple rows using where (two conditions) in sql?

When the condition is based on one column, I can use either IN, AND, or OR, but if the condition is based on two columns, how to write the query? For example, I need to set up the value of column 1 to NULL in the following rows: column 2 = ‘red’ AND column 3 =’ Monday’, column 2 = ‘yellow’ and column 3 = ‘Tuesday’. ‘red’ or ‘yellow’ is not unique in column 2, the same for ‘Monday’ and ‘Tuesday’. I have quite of few of rows need to be updated. How can I do this in one query?

The results look like this:

Advertisement

Answer

WHERE clauses boil down to a simple true/false value: true – the row matches, so do something. false – no match, don’t do anything.

If you have multiple independent conditions, then

And each of those sub-conditions can be as arbitrarily complicated/simple as you need, including having their own in clauses:

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