rzeznik
rzeznik

Reputation: 91

How to load values from file to mysql, where in (file)

I need to make select where id in ( and here i want to load text file, with one int value per one line)

Any help would be appreciated

Upvotes: 6

Views: 4235

Answers (2)

Andrey Portnov
Andrey Portnov

Reputation: 119

You have to use temporary table

CREATE TEMPORARY TABLE `temp` (`id` bigint(20) NOT NULL, PRIMARY KEY(`id`))

then load data from file using

LOAD DATA INFILE ...

and then select your data using temporary table

SELECT * FROM some_table s, temp t WHERE s.id = t.id

Upvotes: 5

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521379

Because your input text file has only one int value per line, you should be able to get away with this:

LOAD DATA INFILE 'input.txt' INTO TABLE yourTable

Upvotes: 2

Related Questions