Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. mysql> describe locations;
  2. +----------------+----------------------------+------+-----+---------+----------------+
  3. | Field | Type | Null | Key | Default | Extra |
  4. +----------------+----------------------------+------+-----+---------+----------------+
  5. | location_id | int(4) | NO | PRI | NULL | auto_increment |
  6. | location_name | varchar(100) | YES | | NULL | |
  7. +----------------+----------------------------+------+-----+---------+----------------+
  8.  
  9. mysql> describe locations_contacts;
  10. +---------------+--------------+------+-----+---------+----------------+
  11. | Field | Type | Null | Key | Default | Extra |
  12. +---------------+--------------+------+-----+---------+----------------+
  13. | contact_id | int(6) | NO | PRI | NULL | auto_increment |
  14. | location_id | int(4) | YES | | NULL | |
  15. | contact_name | varchar(100) | YES | | NULL | |
  16. +---------------+--------------+------+-----+---------+----------------+
  17.  
  18. select a.location_id, a.location_name, b.contact from locations as a
  19. left join (
  20. select location_id, contact_name as contact
  21. from locations_contacts
  22. group by location_id
  23. ) as b on (a.location_id = b.location_id)
  24. where (location_name like '%wesleyan%' or contact like '%wesleyan%')
  25. order by location_name;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement