I have a database with entries similar to the following…
users: +-----+------+----------+---------+-------+ | UID | Name | Addr | City | State | +-----+------+----------+---------+-------+ | 1 | John | 101 Main | Austin | TX | | 2 | John | 101 Main | Houston | TX | | 3 | John | 101 Main | Del Rio | TX | | 4 | John | 101 Main | Houston | TX | +-----+------+----------+---------+-------+ verification: +-----+---------------+--------------+ | UID | LicenseFirst3 | LicenseLast3 | +-----+---------------+--------------+ | 1 | 554 | 122 | | 2 | 556 | 345 | | 3 | 555 | 382 | | 4 | 555 | 108 | +-----+---------------+--------------+ section_user_map: +-----+-----------+---------------------+ | UID | SectionID | CompleteDate | +-----+-----------+---------------------+ | 1 | 65 | 2012-05-12 05:05:15 | | 2 | 72 | 2012-05-06 14:03:15 | | 3 | 65 | 2012-05-09 16:13:15 | | 4 | 72 | 2012-05-06 18:14:15 | +-----+-----------+---------------------+
I need to be able to search for students who completed section 65 between noon on day X and noon on day Y. I also need to show the student’s name, address, city, state and first and last three digits of their license number. I believe this will require both a left join and union command but it’s getting a bit too complicated to formulate.
See it on sqlfiddle.
No
UNIONrequired. Outer join would only be required if you still want to return results for users who do not exist in one (or both) of theusersorverificationtables.