Hi all,
I'm trying to find a way to keep a SELECT from failing if a WHERE condition is false.
This is an extreme simplification of the actual query but I think it'll illustrate the problem. In the scenario below, I need a list of all schools in the school table and, if a school has an entry in the stadium field, I need the stadium name as well.
When I run the query below, though, it fails to return school 1 since there's no stadim zero. How can I select all the schools and still get the stadium name when a valid stadium is given in the school table?
Thanks in advance,
I'm trying to find a way to keep a SELECT from failing if a WHERE condition is false.
This is an extreme simplification of the actual query but I think it'll illustrate the problem. In the scenario below, I need a list of all schools in the school table and, if a school has an entry in the stadium field, I need the stadium name as well.
When I run the query below, though, it fails to return school 1 since there's no stadim zero. How can I select all the schools and still get the stadium name when a valid stadium is given in the school table?
Thanks in advance,
Code:
mysql> select * from school;
+------+---------+---------+
| id | name | stadium |
+------+---------+---------+
| 1 | Able | 0 |
| 2 | Baker | 1 |
| 3 | Charlie | 2 |
+------+---------+---------+
3 rows in set (0.01 sec)
mysql> select * from stadium;
+------+---------------+
| id | name |
+------+---------------+
| 1 | Tiger Stadium |
| 2 | Bears Stadium |
+------+---------------+
2 rows in set (0.00 sec)
mysql> select school.id,school.name,stadium.name from school, stadium where school.stadium = stadium.id;
+------+---------+---------------+
| id | name | name |
+------+---------+---------------+
| 2 | Baker | Tiger Stadium |
| 3 | Charlie | Bears Stadium |
+------+---------+---------------+
2 rows in set (0.00 sec)