MYSQL Wildcard in IN clause is it possible

  • suohryu
  • Born
  • Born
  • suohryu
  • Posts: 2

Post 3+ Months Ago

Hi all just wondering a question that seems simple so i have posted it here

i was wondering if its possible to do something like this

SELECT * FROM `table` WHERE `field` IN ('%var%','%var%','%var%','%var%')

or if there is something like this that doesn't require me to do 10000 query's

well look forward to hearing your replies
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Code: [ Select ]
WHERE field LIKE '%var%'
OR field LIKE '%var2%'
OR field LIKE '%var3%'
  1. WHERE field LIKE '%var%'
  2. OR field LIKE '%var2%'
  3. OR field LIKE '%var3%'
  • suohryu
  • Born
  • Born
  • suohryu
  • Posts: 2

Post 3+ Months Ago

joebert wrote:
Code: [ Select ]
WHERE field LIKE '%var%'
   OR field LIKE '%var2%'
   OR field LIKE '%var3%'
  1. WHERE field LIKE '%var%'
  2.    OR field LIKE '%var2%'
  3.    OR field LIKE '%var3%'


hi thanks for the replay
i thought i would give a bit more detail as the above is acting right in the way it should but now cos of the or statements it ignores the rest of the code

Code: [ Select ]
$t = time();
$quicksearch = "`codes` LIKE '%var%' OR `codes` LIKE '%var2%' OR `codes` LIKE '%var3%';
$sql = "SELECT * FROM `coupons` WHERE `ts_listing` < '$t' AND `ts_expiry` > '$t' AND $quicksearch ORDER BY `coupon id`";
  1. $t = time();
  2. $quicksearch = "`codes` LIKE '%var%' OR `codes` LIKE '%var2%' OR `codes` LIKE '%var3%';
  3. $sql = "SELECT * FROM `coupons` WHERE `ts_listing` < '$t' AND `ts_expiry` > '$t' AND $quicksearch ORDER BY `coupon id`";


i think i am explaining it right if not please let me know
but just to add
so $t is a time stamp im using to compare weather the item is active or not so i do need to include these in the statement and its crucial that they are checked and taking into account because how it stands now because of the or's in the statements its listing things that are not active

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 125 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.