Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

my query is only returning single values

$
0
0
hi everyone

my sql query to a mySQL database is returning incorrect values and i was wondering whehter somone could give me advice on where i went wrong

basically there are 3 tables ;

  1. u.user - the table of the members of the site i.e the user_id of members.
  2. col- countrylist- this is a list of every country in the world. i.e the name of country and the country_id
  3. cl. countrylocation - this is the link between the users and countrylist table. i.e the user_id and the country_id
i now need to draft an SQL query that will enable me to obtain the user_id of each member and also obtain information on what country they are located in.

my query is below


PHP Code:


SELECT 
                 u
.user_id
                  
u.first_name
                  
cl.country_id,
                  
col.country
                      
 
  FROM 
                          users u  
                 LEFT OUTER  JOIN   countrylocation cl
                    ON u
.user_id cl.country_id
                  LEFT OUTER  JOIN  countrylist col  
        ON cl
.country_id col.country_id 
        
            GROUP
                BY  u
.user_id 


The problem with the query above is that it only shows once instance of each countyr location.

For example, i have over 30 members who live in the United States, but the query only shows the country location for the first person who lives in the States; it returns a null value for all other residents living in the States.

Does anyone have any idea where i have gone wrong with this query.

warm regards

Andreea

Viewing all articles
Browse latest Browse all 13329

Trending Articles