Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. lot
  2. id | name | manager_id
  3. ----+------+------------
  4. 1 | foo | 1
  5. 2 | bar | 1
  6.  
  7. manager
  8. id | name
  9. ----+--------
  10. 1 | alice
  11. 2 | bob
  12.  
  13. car
  14. id | lot_id
  15. ----+--------
  16. 1 | 1
  17. 2 | 1
  18. 3 | 2
  19. 4 | 2
  20.  
  21. id | lot_name | manager_id | manager_name | num_cars
  22. ----+----------+------------+--------------+----------
  23. 1 | foo | 1 | alice | 2
  24. 2 | bar | 1 | alice | 2
  25.  
  26. -- manager_id 1 is alice.
  27.  
  28. select
  29. id, name as lot_name, manager_id,
  30. (select name from manager where id = 1) as manager_name
  31. from lot where manager_id = 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement