Advertisement
Guest User

LBD2

a guest
Feb 11th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.65 KB | None | 0 0
  1. --If you know the name of the students who are studying science subject, you can get their id's by using this query below,
  2.  
  3. SELECT id, first_name
  4. FROM student_details
  5. WHERE first_name IN ('Rahul', 'Stephen');
  6.  
  7. --but, if you do not know their names, then to get their id's you need to write the query in this manner,
  8.  
  9. SELECT id, first_name
  10. FROM student_details
  11. WHERE first_name IN (SELECT first_name
  12. FROM student_details
  13. WHERE subject= 'Science');
  14.  
  15. Subquery Output:
  16. ----------------------
  17. | student details    |
  18. |--------------------|
  19. |  id   | first_name |
  20. |-------|------------|
  21. | 100   | Rahul      |
  22. | 102   | Stephen    |
  23. ----------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement