Guest_imported
New member
- Jan 1, 1970
- 0
Hello,
I wanted to consult you with a little dilema I have.
I have a table in my db that looks like this -
id,zone_name
id is unique, there can be many id using the same zone_name.
I need to count how many id's I have for each zone_name.
I have a list of zone_names to be checked.
Zone_List={X,Y,.....}
The lenght of the array is changing and can be between 0 to 10000.
I have 2 ways of doing it:
one is by using a GROUP BY query as followed -
select zone_name,count(id) from <table> where zone_name in Zone_List group by zone_name
Or,the other is by peforming select queries in a loop:
for (i=0;i<Zone_List.length;i++){
select zone_name,count(id) from <table> where zone_name=Zone_List
}
Which is a better way to do it (SQL performance)?
Thanks
I wanted to consult you with a little dilema I have.
I have a table in my db that looks like this -
id,zone_name
id is unique, there can be many id using the same zone_name.
I need to count how many id's I have for each zone_name.
I have a list of zone_names to be checked.
Zone_List={X,Y,.....}
The lenght of the array is changing and can be between 0 to 10000.
I have 2 ways of doing it:
one is by using a GROUP BY query as followed -
select zone_name,count(id) from <table> where zone_name in Zone_List group by zone_name
Or,the other is by peforming select queries in a loop:
for (i=0;i<Zone_List.length;i++){
select zone_name,count(id) from <table> where zone_name=Zone_List
}
Which is a better way to do it (SQL performance)?
Thanks