My Second Table is countries table. It also has a fields called "country_id" and "Country_name". See the Below Image.
My Task was that join two tables according to their country_id s and display distinct country_names and their count. See the Following Output.
So I have to Add Following mysql query to my code.
SELECT DISTINCT( `countries`.`country_name` ) AS country_name, Count(`customers`.`country_id`) AS country_count FROM `customers` INNER JOIN `countries` ON `customers`.`country_id` = `countries`.`country_id` GROUP BY `countries`.`country_name` HAVING `country_count` > 1 ORDER BY country_count DESC
Above sql query works for me to get above output.
0 comments:
Post a Comment
Ask anything about this Tutorial.