MySQL Dynamicly determine the tabel to use with inner join

Posted by user366990 on Stack Overflow See other posts from Stack Overflow or by user366990
Published on 2010-06-15T07:33:07Z Indexed on 2010/06/15 7:42 UTC
Read the original article Hit count: 265

Filed under:
|
|

He guys, I'm stuck with a problem and I hope someone can help me out. I have a date. For example 2009-10-1. This date is used to check in which season I am working. This could be summer or winter.

If whe are in the summer the table to use for my inner join whould be 'summer09_rooms'. If winter 'winter09_rooms'. So I basicly whant to do a CASE WHEN in my INNER JOIN. How to accomplish this. The query would look like this:

SELECT name, arrival_date, departure_date FROM holliday a
INNER JOIN 
(
CASE when arrival_date BETWEEN 2009-10-1 AND 2009-4-1 THEN summer09_rooms b 
ELSE winter09_rooms b END
)
ON a.dossier=b.dossier

Of course this query isn't working but now I hope you'l see what I want to accomplish.

Kind regards,

Digital Human

© Stack Overflow or respective owner

Related posts about mysql

Related posts about join