0

Both of the following queries work perfectly for me at the moment giving out the same results. Which one of the following two are more preferable for huge databases in the long run? Or say, technically which one of these two is a better approach?

SELECT m.* FROM members AS m
LEFT JOIN swipes AS s ON m.mem_id = s.swp_to AND s.swp_by = :mem
WHERE m.mem_id <> :mem AND s.swp_id IS NULL

SELECT m.* FROM members m
WHERE m.mem_id <> :mem
AND NOT EXISTS (SELECT 1 FROM swipes WHERE swp_by = :mem AND swp_to = m.mem_id) 

Keeping in mind the future and the heavy users database which one should I go with?

  • 2
    Sounds like a request for premature optimization. I would recommend building a representative dataset, testing both solutions, and asking a question if you get something unexpected to you. – GMB Mar 12 '20 at 23:02
  • 1
    Have you compared their [`EXPLAIN` plans](https://dev.mysql.com/doc/refman/8.0/en/explain.html)? – Phil Mar 12 '20 at 23:03
  • 2
    It's always quicker to test this kind of thing for yourself than to ask us. But I'll buy you an iced tea if the first one's quicker on a properly indexed dataset. – Strawberry Mar 12 '20 at 23:08
  • @SlavaRozhnev and why so? – Shreyansh Kashyap Mar 12 '20 at 23:08

0 Answers0