Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. select distinct A.id
  2. from A inner join B on B.a_id = A.id
  3. where B.x >= 5 and B.x <= 10;
  4.  
  5. select A.id
  6. from A
  7. where A.id in (select B.a_id from B where B.x > 5)
  8.  
  9. select A.id
  10. from A
  11. where exists (select 1 from B where b.x > 5 and b.a_id = a.id limit 1)
  12.  
  13. SELECT DISTINCT a_id AS id
  14. FROM B
  15. WHERE x >= 5 and x <= 10 ;
  16.  
  17. SELECT a_id AS id
  18. FROM B
  19. GROUP BY a_id
  20. HAVING MAX(x) >= 5
  21. AND MIN(x) <= 10 ;
  22.  
  23. SELECT A.*
  24. FROM A
  25. JOIN
  26. ( SELECT a_id
  27. FROM B
  28. GROUP BY a_id
  29. HAVING MAX(x) >= 5
  30. AND MIN(x) <= 10
  31. ) AS b
  32. ON b.a_id = a.id ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement