Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mysql> describe locations;
- +----------------+----------------------------+------+-----+---------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +----------------+----------------------------+------+-----+---------+----------------+
- | location_id | int(4) | NO | PRI | NULL | auto_increment |
- | location_name | varchar(100) | YES | | NULL | |
- +----------------+----------------------------+------+-----+---------+----------------+
- mysql> describe locations_contacts;
- +---------------+--------------+------+-----+---------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +---------------+--------------+------+-----+---------+----------------+
- | contact_id | int(6) | NO | PRI | NULL | auto_increment |
- | location_id | int(4) | YES | | NULL | |
- | contact_name | varchar(100) | YES | | NULL | |
- +---------------+--------------+------+-----+---------+----------------+
- select a.location_id, a.location_name, b.contact from locations as a
- left join (
- select location_id, contact_name as contact
- from locations_contacts
- group by location_id
- ) as b on (a.location_id = b.location_id)
- where (location_name like '%wesleyan%' or contact like '%wesleyan%')
- order by location_name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement