i want to select itinerary_id, itinerary_description and, if it
exists, the schedule departure date. but if there is no departure
date, no schedule data, i still need the itinerary info. i have no
idea how to accomplish this. any and all ideas would be massively
appreciated.
What have you tried? Look at the left outer join and case statements.
Case is not mandatory - if returning NULL is sufficient.
Given:
mysql> select * from a;
+---+------+------+
| z | a | b |
+---+------+------+
| 1 | a | 1 |
| 2 | a | 2 |
+---+------+------+
2 rows in set (0.01 sec)
mysql> select * from b;
+------+------+
| a | b |
+------+------+
| b | 2 |
| c | 3 |
+------+------+
EXAMPLE:
mysql> select a.a, a.b, case when b.a is null then 'NoData' else b.a end
as c
-> from a a left outer join b b on a.b=b.b where a.b=1;
+------+------+--------+
| a | b | c |
+------+------+--------+
| a | 1 | NoData |
+------+------+--------+
I hadn't tried anything cuz i didn't know where to start. Trying to
explain things as clearly as i could in the original post made me
think LEFT join, so i started googling that. I found this page,
http://www.wellho.net/solutions/mysql-left-joins-to-link-three-or-more-tables.html,
which explained it to me. If fact my above explanation was
oversimplified. I had three tables. Understanding left join was the
key. Thanks for the help.