I’m not sure if this is possible with an SQL query alone, but I basically want to create a table like this but with a condition on the course type field that stores ‘futher’ or ‘higher’ as a number based on what the ‘course_type’ is:
CREATE TABLE IF NOT EXISTS `courses_index` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` text COLLATE utf8_unicode_ci NOT NULL,
`url` text COLLATE utf8_unicode_ci NOT NULL,
`further` int(1) NOT NULL,
`higher` int(1) NOT NULL,
PRIMARY KEY (`id`),
FULLTEXT `index` (title, url, course_type)
) AS SELECT title, url, course_type FROM `courses`
My course_type field on the courses table is a standard text field that will contain a string such as "Higher, Further" or "Further".
I want to be able to say if this course_type field is LIKE %higher% then the value of the row is 1. Likewise if the value of course_type is LIKE %higher%further then both fields are stored as a 1, etc.
Is this possible by means of creating a temporary table, or a clever MySQL query?
Many thanks in advance
Tim
The following should work:
EDIT fixed broken syntax
See also this sqlfiddle