user2217149
user2217149

Reputation: 11

passing a subquery result in IN clause of a query

I want to use the result returned by a sub query into the IN clause of the other query in mysql i want to do something like BULK COLLECT one do in oracle database but I guess nothing like that is available in mysql

For ex :

set @features := (select group_concat(apf.featureid ) from 
applicationpackagefeature apf ,
feature f,
applicationpackage ap,
applicationpackageapplication apa,
application a
where f.id = apf.featureid
and apf.applicationPackageId = ap.id
and apa.applicationPackageId = ap.id
and apa.applicationId = a.id
and a.platform = 'b'
and a.version = 'a'
and a.name = 'c');

I want to store the id's returned by this query and use it in three set set od delete statement though i have used group_concat but it is not working

delete from applicationpackagefeature where featureid in (
    @features 
)

Upvotes: 0

Views: 43

Answers (1)

Omesh
Omesh

Reputation: 29111

You can achive this using Prepared Statements in MySQL:

SET @query = CONCAT('delete from applicationpackagefeature where featureid in (
',@features,')');

PREPARE stmt FROM @query; EXECUTE stmt; DEALLOCATE PREPARE stmt;

Upvotes: 1

Related Questions