6

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

2
  • Does your input file have a header line, or does the first line contain data? Commented Apr 13, 2016 at 9:23
  • 1
    first line contains data Commented Apr 13, 2016 at 9:27

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

Comments

2

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

2 Comments

but i dont want to insert values into table, i need to make query like this: select * from users where id in (file with int values)
MySQL doesn't operate this way. If the data be located in a file, you should first load it into a table. Afterwards, you can query as you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.