Link to home
Start Free TrialLog in
Avatar of Dakdouk Roula
Dakdouk Roula

asked on

Printing different fields that have a common column value

I created in mariadb a table “countrystatistic”   with a CountryName varchar(50), PrimaryLanguage varchar(50) and population int(11). I then insert it several countries.

I’m trying to write a query that would print the countries that share the same primary language. Somehow it’s not working out completely. I have this query but this one doesn’t print ALL the coutries with the common language.

SELECT ALL PrimaryLanguage,COUNT(Primarylanguage),CountryName
FROM countrystatistic
GROUP BY PrimaryLanguage
HAVING COUNT(PrimaryLanguage) > 1;


I tried using a lot of queries with Join. I either got only part of the answer or an error this gave me an error:

SELECT DISTINCT A.PrimaryLanguage, A.CountryName, B.CountryName
From countrystatistic A, countrystatistic B
Where A.PrimaryLanguage = B.PrimaryLanguage
AND A.count(PrimaryLanguage) > 1;

Can someone help me with this? Thank you!
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please you can try this query and I hope it solves your need......


SELECT  A.PrimaryLanguage,
                A.CountryName,  
                B.LanguageCount  
FROM countrystatistic A,
   (SELECT  PrimaryLanguage,COUNT(Primarylanguage) AS LanguageCount  
    FROM countrystatistic
     GROUP BY PrimaryLanguage
     HAVING COUNT(PrimaryLanguage) > 1) B
WHERE A.PrimaryLanguage =B.PrimaryLanguage ORDER BY 3 DESC


Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

>>Please you can try this query and I hope it solves your need......

Produces the same results as mine and mine only accesses the table once.
Avatar of Dakdouk Roula

ASKER

Thank you all for your help! I got the desired result  :)