user1007522 user1007522 - 1 year ago 42
SQL Question

SQL subqueries what has the best performance

I'm having a question about this SQL query:

SELECT class
FROM Ships
WHERE name IN (SELECT ship
FROM Outcomes
WHERE result = ’sunk’);

Can I write in the subquery
SELECT * From Outcomes
or do I always need to

And what query has the best performance then?

Answer Source

You can't put * in this subquery. The best way to do it is:

SELECT class
  FROM Ships s
 WHERE exists
        select 1 
          from Outcomes o
        where = o.ship
          and result = ’sunk’