Sangoku
Sangoku

Reputation: 1606

Use nested select query in a where clausle MySql

Hello i have a very old and BIG query which gous like this:

select id, someValue, (select x from y inner join x on x.y = y.zzz) as filter

Now i need to filter for the deliverd variable like

select id, someValue, (select x from y inner join x on x.y = y.zzz) as filter
WHERE filter not 'badPractise'

Is there any way i can use it without making the same join in the where clausule?

Upvotes: 1

Views: 416

Answers (1)

M Khalid Junaid
M Khalid Junaid

Reputation: 64466

Yes you can use HAVING clause to filter out with your filter column

select id, someValue, 
(select x from y inner join x on x.y = y.zzz) as filter
FROM ....
HAVING filter <> 'badPractise'

Upvotes: 1

Related Questions