Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 14th, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Display null for column if no row found
  2. SELECT s.first_name, s.last_name, tgs.group_identifier
  3. FROM staff s
  4. JOIN staff_training st
  5. ON s.staff_id = st.staff_id
  6. JOIN training_group_staff tgs
  7. ON st.staff_training_id = tgs.staff_training_id
  8. WHERE st.staff_course_id = '164'
  9.        
  10. first_name  |  last_name  |  group_identifier
  11.  Jim        |   Jones     |   3
  12.  Harry      |   Jones     |   6
  13.        
  14. first_name  |  last_name  |  group_identifier
  15.  Jim        |   Jones     |   3
  16.  Harriet    |   Smith     |   NULL   // No row in training_group_staff
  17.  Harry      |   Jones     |   6
  18.        
  19. SELECT s.first_name, s.last_name, tgs.group_identifier
  20. FROM staff s
  21. JOIN staff_training st
  22. JOIN ON s.staff_id = st.staff_id
  23. LEFT OUTER JOIN training_group_staff tgs
  24. ON st.staff_training_id = tgs.staff_training_id
  25. WHERE st.staff_course_id = '164'