How to select row where 2 of 3 columns are not empty?


I would like to select a row where 2 of 3 columns are not empty. Is there any short cut to doing this?

So far, I have this: “SELECT * FROM table WHERE (first != ‘’ AND second != ‘’) OR (first != ‘’ AND third != ‘’) OR (second != ‘’ AND third != ‘’))”;

This works, but I was wondering if there was a more efficient way of doing it.


not exactly a shortcut, because it requires a bit of work now, but will likely save you scads of time later, as well as being more efficient…

redesign the table :slight_smile:

instead of three different columns, you should have only one column, with three rows

what actual data is being stored in the “first, second and third” columns?

Well, I have items for sale and a large table with about 30 columns.

Now I am experimenting with a Google product feed, which requires that each item have certain fields exist before it will be allowed on the live feed.

A requirement is that 2 of 3 be available: brand name, upc or mpn.

I can’t picture putting these all into one column. Let me know if you can think of a better way to select these items.

Kind regards

me neither, because those are different data attributes

certainly a lot more to go on than “first, second, and third”

brand name, upc or mpn do not need to be redesigned

what you have is fine, except i would be concerned about those zero-length strings – i would use NULLs instead