Moon_Watcher
Moon_Watcher

Reputation: 468

Executing different queries depending on case statement

I have a column called 'Measure', which contains multiple values. When the value of this columns is 'Majors', I want to execute the following:

select *
from students;

And when the value is anything else, I want to execute:

select distinct *
from students;

I have used CASE statements in the past to return a single value. How can they be made to return an entire query? Alternatively, how can this problem be approached without CASE?

Any help is appreciated.

Upvotes: 0

Views: 294

Answers (1)

Alex
Alex

Reputation: 371

I'd give a try at this. Basicly, it gives you all the results for Majors and then adds up the other results.

SELECT * FROM students
WHERE Measure = 'Majors'
UNION
SELECT DISTINCT * FROM students
WHERE Measure <> 'Majors'

Upvotes: 2

Related Questions