Jump to content

How to keep from repeating subquery in where clause


tibberous

Recommended Posts

I have a query like:

 

select * from users where (select `State` from `locations` where `locations`.`id`=`users`.`id`)!='PA' or (select `State` from `locations` where `locations`.`id`=`users`.`id`)!='NJ' or (select `State` from `locations` where `locations`.`id`=`users`.`id`)!='NY' or (select `State` from `locations` where `locations`.`id`=`users`.`id`)!='TX' ... ect

 

This is obviously terrible - if only because it makes the query impossibly long to read. How can I get around this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.