I'm trying to figure out which of the following ways would be the best if I am concerned about speed and efficiency. I'll be using PHP and MySQL. Let's say that I have 1000 numbers in the database for each account (1000's of accounts). When I get a new number I need to check to make sure that it isn't already in the database. Numbers will be checked once or twice an hour. Which would be better to store the data? 1) Store all of the numbers for the accounts in seperate rows. Cons: Excessive rows. Could eventually be more CPU intensive with millions and millions of rows. 2) Store all of the numbers for the accounts in an array in 1 row Cons: 1000's of numbers in 1 field. More CPU intensive searching the array? Not sure. NOW which way would be better to query the data? 1) select * from numbers where account='1' and number='NEW_NUMBER'; OR select * from numbers where account='1' and number LIKE '%NEW_NUMBER%'; if using an array Cons: A lot of queries if I have to do this for every new number that I am checking for 2) Use an OR between every new number. Use PHP to construct the OR side of the query. select * from numbers where account='1' and number='1' or number='2' or number='3' or number='4' or number='5' or number='1000'; Cons: A very large single query if we are taking about checking 1000+ numbers. Change = to LIKE if using array. I hope this doesn't confuse you. If you have a better solution please let me know.
I'm with T0PS (not literally) #1 is the best option and you could always do that in one query too select * from numbers where account='1' and number in ('1', '2', '3') Code (sql):
Thanks guys. I've never used IN before. I'll check it out. BTW - When I used "array" above I meant delimited.