I'm trying to automatically populate members into a newsletter script. There are two groups NFL and College.
DATABASE 1 is from a joomla website where users are subscribed to different plans. I need to get the names and email from these users and enter them into either the NFL newsletter, College Football newsletter, or both based on their plan_id.
Basically I need a 2 different queries for 2 different databases.
1. To get name and email from DATABASE1 based on data from 2 tables.
2. To insert name and email into 2 separate groups in DATABASE2
I need to get the names and emails of all users from TABLE1, and who have A under status column and divide them into two groups based on which plain_id they have from TABLE2.
plan_id 1 goes into both, plan id 2 goes into group1, plan_id 3 goes into group2
The linking columns would be "id" for DATABASE1-TABLE1, and "user_id" for DATABASE1-TABLE2.
Once i have the names and emails for both separate Groups, I would need to INSERT them into DATABASE2
I hope this makes sense.
If someone can logically suggest how I can go about this I would really appreciate it.
Data from 2 Tables MySQL
Page 1 of 1
Need some help with query
1 Replies - 822 Views - Last Post: 10 September 2009 - 04:22 AM
Replies To: Data from 2 Tables MySQL
Re: Data from 2 Tables MySQL
Posted 10 September 2009 - 04:22 AM
SELECT `table1`.`name`, `table1`.`email`, `table2`.`status` FROM `table1` LEFT JOIN `table2` ON `table1`.`user_id` = `table2`.`id` WHERE `table2`.`status` = 'A';
Should work fine, consider taking a look at LEFT JOIN.
Page 1 of 1