0

I'm trying to count the amount of items on a table that have a certain tag on them, coded as a number. I have the numbers I want to count in a txt file, but can't figute out how to take the info from the file directly to my query.

Writing them down the code would look like:

 SELECT ID, COUNT(*) FROM table WHERE ID IN ('0102','1123','1314',1340') GROUP BY 1;

And the expected output should be the number of entries that have any of the IDs on the list.

The problem with this approach is that in some cases the amount of IDs is too big. Is there any way to get the IDs from the original file and use them on the query?

Thanks.

Hjorvik
  • 61
  • 6

1 Answers1

2

If this is a one time job then the best way to do this would be to import the data into a temp table with one record per item id in the text file. After that, all you need it is a simple inner join query.

How to import text data into MySql

SELECT * FROM table WHERE ID IN(SELECT ID FROM TempData)
Ross Bush
  • 14,648
  • 2
  • 32
  • 55