I am just curious on how to make sure that the query returns null values too along with other values.
UPDATE: The following query is supposed to output a table with a location id, visit date visit time and bus name for each visits. The query below gives the output but does not include the nulls like in the table below. The result should include nulls also.
There are 3 tables in total: Location1, bus & visit. So I am using this(below) query to extract IDs and join all the tables. The query looks for visits only to Florida.
For instance, take the following query:
SELECT LOC.LOC_ID, VISIT.VISIT_DATE, VISIT.VISIT_TIME, BUS.BUS_NAME
FROM BUS, LOCATION1, VISIT
WHERE VISIT.BUS_ID = BUS.BUS_ID
AND VISIT.LOC_ID = LOCATION1.LOC_ID
AND BUS.BUS_NAME IN (
SELECT BUS_NAME
FROM BUS
WHERE BUS_ID IN (
SELECT BUS_ID
FROM VISIT
WHERE LOC_ID IN (
SELECT LOC_ID
FROM LOCATION1
WHERE LOC_NAME='Florida')));
Let us suppose, there are visits which have not yet been assigned a bus and thus some values are null
.
So, from what I believe using IN
operator will return set of values but not the null
values. What if i use exists
instead?
The table can look like this:
Loc_name Loc_id visit_date visit_time bus_name
Florida 1 26-mar-2009 2:00pm xyz
Florida 3 29-jul-2010 3:00pm abc
Florida 8 22-may-2013 2:50pm (null)
.
.
.
hope someone can help me with this.
thanks
UPDATE 2:
Found the Answer!
SELECT LOC.LOC_ID, VISIT.VISIT_DATE, VISIT.VISIT_TIME, BUS.BUS_NAME
FROM LOCATION1
LEFT JOIN VISIT ON LLOCATION1.LOC_ID = VISIT.LOC_ID
LEFT JOIN BUS ON BUS.BUS_ID = VISIT.BUS_ID
WHERE LOC_NAME = 'Florida';
Thanks again!