Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Querying using multiple LIKEs from same column?

Tags:

sql

mysql

My database is listing Jobs. I want a user to be able to query jobs from a particular industry but chose as many work-types from the type column as they want, eg:

SELECT * FROM `rec_jobs` 
WHERE `industry` LIKE '%Security%' AND 
   (`type` LIKE '%Full-Time%' OR 'type' LIKE '%Part-Time%' OR 'type' LIKE '%Casual%' OR 'type' LIKE '%Contract%');

This should return something like:

ID - Industy - Type


1 - Security - Part-Time

2 - Security - Full-Time

3 - Security - Casual

4 - Security - Full-Time

etc.

but it is not working as expected - I dont get any SQL errors or any results (though I know rows exist).

Does anyone know a better way of achieving this (or the correct terminology to search in Google)?

like image 771
MeltingDog Avatar asked Sep 01 '26 20:09

MeltingDog


1 Answers

you should use the same quotes around the column name type:

SELECT *
FROM `rec_jobs`
WHERE `industry` LIKE '%Security%'
    AND (
        `type` LIKE '%Full-Time%'
        OR `type` LIKE '%Part-Time%'
        OR `type` LIKE '%Casual%'
        OR `type` LIKE '%Contract%');
like image 130
Jens Avatar answered Sep 03 '26 08:09

Jens