Basically I’m trying to combine two tables together into a new table. The first table contains information on users and the second table stores information on purchases along with address specific information.
The end result would be a new updated table for Users that now includes addresses for each user (eg. zipcode, state, country) that will be merged from the Deals_Users_Assoc table.
Here’s the query that I have so far:
INSERT INTO NewUsers (User_ID, FirstName, LastName, City, StateProvince, Country, ZipCode, Username, Username_Clean, Password, Email, ActivationToken, LastActivationRequest, LostPasswordRequest, Active, Group_ID, SignUpDate, LastSignIn)
SELECT DISTINCT a.User_ID, a.FirstName, a.LastName, b.address_city, b.address_state, b.address_country, b.address_zip, a.Username, a.Username_Clean, a.Password, a.Email, a.ActivationToken, a.LastActivationRequest, a.LostPasswordRequest, a.Active, a.Group_ID, a.SignUpDate, a.LastSignIn
FROM Users a, Deals_Users_Assoc b
WHERE a.User_ID = b.user_id
GROUP BY a.User_ID;
It’s working, but only inserting data for users that are also stored in the Deals_Users_Assoc table (WHERE a.User_ID = b.user_id). Hundreds of user id’s are still remaining in the Users table.
Any help would be appreciated!
Try to use SELECT query with LEFT JOIN clause –