I am working to join the contents of my tables, I am trying to join two tables while still getting the results from table 'movies' even if there is no matching record in table 'users_ratings'. But it seems not working I get only one result.
--movies Table (100 records)
CREATE TABLE IF NOT EXISTS `movies` (
`ID` int(20) NOT NULL,
`title_name` vachar(255) NOT NULL,
`creation_date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--ratings Table (1 records)
CREATE TABLE IF NOT EXISTS `users_ratings` (
`ID` int(20) NOT NULL,
`user_id` bigint(20) NOT NULL,
`type_id` bigint(20) NOT NULL,
`type_name` vachar(255) NOT NULL,
`score` int(11) NOT NULL,
`creation_date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--My Query
SELECT name_table.*, ur.type_id, count(ur.type_id) vote_count
FROM `movies` name_table
left JOIN users_ratings ur ON name_table.id = ur.type_id
WHERE ur.type_name= 'movies'
GROUP BY ur.type_id
Order BY vote_count DESC
--Query Results
ID title_name creation_date type_id vote_count
1 Avatar 2014-05-20 00:00:00 1 1
--Results I'm trying to get (Should I get 100 records)
ID title_name creation_date type_id vote_count
1 Avatar 2014-05-20 00:00:00 1 1
2 Avengers 2014-05-20 00:00:00 NULL NULL
3 Ant-Man 2014-05-20 00:00:00 NULL NULL
4 Jurassic World 2014-05-20 00:00:00 NULL NULL
5 Rampage 2014-05-20 00:00:00 NULL NULL
6 Black Panther 2014-05-20 00:00:00 NULL NULL
7 Tombe Raider 2014-05-20 00:00:00 NULL NULL
8 Deadpool 2014-05-20 00:00:00 NULL NULL
9 Pacific Rim 2014-05-20 00:00:00 NULL NULL