I have A and B two tables in my mysql database.
create A (
id int primary auto_increment,
....
);
create B (
id int,
status int default 0, /*only between 0 and 2*/
foreign key (id) references A(id) ,
index `index_test`(id, status)
);
Now, I want to get info view from A and B.
create view info
as
select A.id, statistics.status, statistics.status_statistics as ss
from A
left outer join (
select id, status, count(*) as status_statistics
from B
group by(B.id, B.status)
) as 'statistics' on (A.id = statistics.id);
But, this will get Multi-row result rather that one. How to get One?
For example:
table A:
id
--
1
2
table B:
id status
------------
1 0
1 1
1 2
1 0
2 1
I use the above method, I will get:
id status ss
-----------------
1 0 2
1 1 1
1 2 1
2 1 1
Howerver, I want to get:
id | column_name_one | column_name_two | column_name_three
------------------------------------------------------------------------------------------
1 2 1 1
2 0 1 0