Reputation: 384
I have a table that has the following columns: id, session_id, date_start, date_end, speaker_1, speaker_2, speaker_3, speaker_4, speaker_5
I'd like to query this table for all sessions where a speaker_id is contained in any of the 5 speaker columns. I'm also needing to join a table to session_id that contains additional information about the session.
I know that this table structure isn't in the ideal format for what it is I want to do, but I can't get the table structure changed at this point.
I'm curious how to query for the conditional portion of the speaker value at the end. Is it possible to group the columns?
Basic SQL experience here. Thanks!
Upvotes: 0
Views: 40
Reputation: 21508
WHERE :id IN (speaker_1, speaker_2, speaker_3, speaker_4, speaker_5)
Upvotes: 0
Reputation: 1269753
You can use in
:
select s.*
from speakers s
where 1 in (speaker_1, speaker_2, speaker_3, speaker_4, speaker_5);
(Assuming you are looking for 1
as the speaker id.)
You can use variables in the in
list.
Upvotes: 1