Last active
May 27, 2022 12:32
-
-
Save DominikStyp/51320d6d4459e902e6425abae40a1d07 to your computer and use it in GitHub Desktop.
SQL & MySQL: Using local variables in complex queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set @s1 = '%123aaabbbcccdddeeefffggg%'; | |
select * from `items` where | |
( | |
`title` LIKE @s1 or `apn` LIKE @s1 or `slug` LIKE @s1 | |
or exists (select * from `sellers` where `items`.`seller_id` = `sellers`.`id` | |
and (`title` LIKE @s1 or `slug` LIKE @s1 or `address` LIKE @s1) | |
) | |
or exists (select * from `item_geos` | |
where `items`.`id` = `item_geos`.`item_id` | |
and (`state` LIKE @s1 or `acreage` LIKE @s1 or `county` LIKE @s1 or `city` LIKE @s1 | |
or `address` LIKE @s1 or `zip` LIKE @s1 | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment