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!
MySQL ServerSQL

Avatar of undefined
Last Comment
Dakdouk Roula

8/22/2022 - Mon
SOLUTION
slightwv (䄆 Netminder)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Tomas Helgi Johannsson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Karunamoorthy Periyasamy

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


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.
ASKER
Dakdouk Roula

Thank you all for your help! I got the desired result  :) 
Your help has saved me hundreds of hours of internet surfing.
fblack61