jimmie
05-07-2006, 02:01 PM
Hi,
I have a small problem with a query. I know I can solve this by using subquerys but I want to do it without that so please give me some guidance.
I have a table, lets call it animals. In this table there are id,owner,type.
Type can be 0,1,2 -> cat,dog, bird.
What i want to do is create a query that returns this set:
owner, # of cats, #of dogs, #of birds
that means:
owner, count for type 0,count for type 1,count for type 2 on the SAME row.
This is easy to do with subquerys but where talking about a database with millions of rows and this query is just one of many nightly querys so I need it to be as effective as possible. And of course the table is a bit more complex with related tables involved in the query and it's going to be grouped by 2 more parameters but I want to keep it simple for you guys.
I'm looking for a function like group_concat but that puts the data into different fields and not the same... That would be the perfect solution.
I have a small problem with a query. I know I can solve this by using subquerys but I want to do it without that so please give me some guidance.
I have a table, lets call it animals. In this table there are id,owner,type.
Type can be 0,1,2 -> cat,dog, bird.
What i want to do is create a query that returns this set:
owner, # of cats, #of dogs, #of birds
that means:
owner, count for type 0,count for type 1,count for type 2 on the SAME row.
This is easy to do with subquerys but where talking about a database with millions of rows and this query is just one of many nightly querys so I need it to be as effective as possible. And of course the table is a bit more complex with related tables involved in the query and it's going to be grouped by 2 more parameters but I want to keep it simple for you guys.
I'm looking for a function like group_concat but that puts the data into different fields and not the same... That would be the perfect solution.