How to make mysql like and not like fetch strings from a list

user3286430

I have the following mysql code

SELECT * FROM loans_book WHERE the_amount < 500000 
AND 
loan_amount_you_require 
NOT LIKE '%avensis%' 
OR 
loan_amount_you_require  
NOT LIKE '%prius%'
OR
loan_amount_you_require 
NOT LIKE '%porsch%'
OR

the problem is,if i keep adding the not likes,they are bound to add up to 100 and i suspect the list could grow longer.

I like the way mysql has NOT IN where i can comma separate my strings but not like is different in that i need to specify the column name each time.

is there a way i could possibly go around the requirement to state the column name each time i want to use not like?.

RichardBernards

You can try using NOT REGEXP for this... Query should look like the following:

SELECT 
    *
FROM
    loans_book
WHERE
    the_amount < 500000 
    AND loan_amount_you_require NOT REGEXP 'avensis|prius|porsch';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related