Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT INTO OUTFILE WITH "WHERE" statement

Tags:

mysql

I'm trying to export the DB records from the table via "SELECT INTO OUTFILE". Everything works. But I need to filter the records and this is the problem. Here's the code:

SELECT * INTO OUTFILE 'file.txt' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
FROM table_name WHERE name LIKE '%John%' AND LENGTH(name) <= 10 ORDER BY name

This statement doesn't work, but if I remove the "name LIKE '%John%'" condition, it works. But I need to specify this LIKE condition, how can I accomplish it?

Thanks.

like image 832
Dima Knivets Avatar asked Jan 19 '26 08:01

Dima Knivets


1 Answers

Could be a problem with the %sign. Try replacing

WHERE name LIKE '%John%'

with

WHERE LOCATE(name, 'John') > 0
like image 105
juergen d Avatar answered Jan 21 '26 01:01

juergen d