1

I'm not sure if what I'm trying to do is possible at all. I'd like to be able to run a query in MySQL that does a simple Select, but uses the search criteria / select criteria from an external file to do the select on.

e.g.

SELECT * FROM lookup_table WHERE id IN (<import each individual id from external file>);

The id's will then be placed in a file. Reason I'm asking for this is that I can't create temporary tables in the database, but I can execute queries. The external file can be in any format that's required, but will contain a few hundred id's that I need to look up.

Is anything possible?

Coops
  • 13
  • 3
  • It looks like the only way to get data into MySQL is `LOAD DATA INFILE` and it only loads into tables. So perhaps the only way to achieve what you want is to have a table where you `LOAD` the list from the .txt file, and then manipulate it within that subquery or join it to the lookup table. – WAF Jul 06 '15 at 18:21

1 Answers1

0

You could place all the IDs in a list in a .txt file and then use file_get_contents to get the contents. Once you've done that, you can explode the contents by new line (or whatever you seperated the values by).

Prinsig
  • 245
  • 3
  • 9
  • 1
    Just looked up "file_get_contents" and it looks like a PHP command. I'm not using PHP - I was looking for a MySQL command that can be used within mysqld for example. Unless direct PHP can be called from within the mysql console? – Coops May 09 '14 at 12:49