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 ;
my query is below
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
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 ;
- u.user - the table of the members of the site i.e the user_id of members.
- col- countrylist- this is a list of every country in the world. i.e the name of country and the country_id
- cl. countrylocation - this is the link between the users and countrylist table. i.e the user_id and the country_id
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