Selecting a specific value of a column based on a value from another column mysql

Viewed 10

I have a table similar to this:

customer shop available_A available_B available_C
123456 A True True False
. B False True True
. C True False True

I want to only select True values of a specific "available" column based on the specific shop value, so something like:

select (available_A = 'True' where shop = 'A' AND 
available_B = 'True' where shop = 'B' AND
available_C = 'True' where shop = 'C')

All of them at the same script.

1 Answers
select * from shop where 
(shop = 'A' AND available_A = TRUE) OR 
(shop = 'B' AND available_B = TRUE) OR 
(shop = 'C' AND available_C = TRUE)

should do the trick. Although you should restructure your database to have a second table referencing the shop table storing availability.

Related