user1007522 user1007522 - 1 year ago 58
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’
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download