SQL query to search for string in a table?

Viewed 1932

Hi i want to search for a particular string in a table stored in mysql database. The table structure is as follow:-

+--------------------------------------------------------------------------+
|    day    | 9-10    | 10-11  | 11-12    | 12-1  | 1-2    |  2-3   |  3-4 |
|---------------------------------------------------------------------------
| Monday    | DA6210  | DA6220  | DA6010  |       | DA6020 |        |      |
| Tuesday   | DA6210  | DA6010  | DA6220  |       | DA6020 |        |      |
| Wednesday | IA6010  | DA6220  |         |       | DA6020 |        |      |
| Thursday  | IA6010  |         | DA6210  |       | GC6210 |        |      |
| Friday    | IA6010  |         | DA6010  |       | GC6210 |        |      |
| Saturday  | DA6210  |         |         |       |        |        |      |
+--------------------------------------------------------------------------+

I want to search for the string against the day and all the time. For ex. if the day is thursday and code is DA6220 it should return empty set as the string is not there across all the time slots on thursday.

I have created an sql query but it is not working as desired. Kindly please provide a way to do it.

SQl query:-

SELECT * from `table` where day='Thursday' AND `9-10`='DA6220' OR `10-11`='DA6220' OR `11-12`='DA6220' 
            OR `12-1`='DA6220' OR `1-2`='DA6220' OR `2-3`='DA6220' OR `3-4`='DA6220'
3 Answers
Related