September 11th, 2013, 08:03 AM
Select once column depending on value of another column
I want to write a query where I select the value of one column (sep1) only if another column from the same table (alumno1) is not null. How could I do this?
September 11th, 2013, 08:44 AM
I'm guessing that you are asking for something like:
alumno1 IS NOT NULL
September 11th, 2013, 08:55 AM
So how can I expand the query to select various columns with the a specific condition for each column?
that is to say:
Select Sep1 from groups where alumno1 is not null, Sep2 from groups where alumno2 is not null etc
September 11th, 2013, 04:34 PM
Depending on your actual requirement you may want to look at the UNION clause:
"sep1" AS theColumn,
WHERE alumno1 IS NOT NULL
WHERE alumno2 IS NOT NULL
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc
September 11th, 2013, 04:42 PM
chances are good this wouldn't be nearly as difficult if you normalize your data
Originally Posted by Carrilo
whenever you have many columns all with the same name and a numeric suffix, that's a sure sign of a bad data model
do a SHOW CREATE TABLE and we'll help you redesign it
September 14th, 2013, 01:15 PM
The union all query works thanks