Search code examples
mysqlsubquerysql-order-by

Mysql subquery order when using IN


Does the order of the results inside a mysql subquery affect the order of the actual query? I tried it but did not came to a real result cause sometimes it seemed so and sometimes it doesn't.

eg:

SELECT name FROM people WHERE pid IN (SELECT mid FROM member ORDER BY mdate)

Is the "order by"-clause going to affect the order of the results in this case?

Thanks.


Solution

  • No it cant and if you want to change the order as per your need then better use a JOIN

    Something like this:-

    select name 
    from people p inner join member m on p.pid = m.mid
    order by p.name