Reputation: 92581
I am generating the below query as part of our system:
SELECT * FROM (`videos`) WHERE (
`videos`.`title` LIKE "%apple%"
OR WHERE
`videos`.`byline` LIKE "%apple%"
OR WHERE `videos`.`description` LIKE "%apple%"
);
However, this is throwing a syntax error.
So, what's up?
Note that I need the brackets as those three where
's are linked, often followed by separate AND WHERE
's
Upvotes: 1
Views: 2925
Reputation: 94429
Sql statements use single quotes around literal values. Also only one where clause is needed in this case. Simply use one where clause and then use or
to connect the predicates. The script also has some parenthesis that are not required.
The final result looks like:
SELECT * FROM `videos` WHERE
`videos`.`title` LIKE '%apple%' OR
`videos`.`byline` LIKE '%apple%' OR
`videos`.`description` LIKE '%apple%';
Upvotes: 4
Reputation: 6079
Replace "OR WHERE" with "WHERE" and replace double quote with single quote " ---> '
Upvotes: 0
Reputation: 91
is OR WHERE valid SQL? Try this:
SELECT * FROM (`videos`) WHERE (
`videos`.`title` LIKE "%apple%"
OR
`videos`.`byline` LIKE "%apple%"
OR `videos`.`description` LIKE "%apple%"
);
Upvotes: 0