Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL select query in where clause

Can u correct this query? it is show some syntax error.

SELECT * 
 WHERE `id` IN (SELECT DISTINCT unit_trust_managing_company_id 
                  FROM ut_funds 
                 ORDER BY `company_name`)

There SELECT DISTINCT unit_trust_managing_company_id FROM ut_funds ORDER BYcompany_name` query is working properly.

like image 389
Dinuka Thilanga Avatar asked Aug 31 '13 13:08

Dinuka Thilanga


1 Answers

You need a from clause before the where:

SELECT *
FROM <some table here>
WHERE `id` IN (SELECT unit_trust_managing_company_id FROM ut_funds)

Also, the distinct and order by are not needed for the in statement.

like image 71
Gordon Linoff Avatar answered Sep 22 '22 16:09

Gordon Linoff