Data from 2 Tables MySQL

Need some help with query

Page 1 of 1

1 Replies - 590 Views - Last Post: 10 September 2009 - 04:22 AM Rate Topic: -----

#1 whatshakin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-April 09

Data from 2 Tables MySQL

Post icon  Posted 09 September 2009 - 11:15 PM

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.

(Pictures included)

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.
Posted Image
Posted Image



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.

Is This A Good Question/Topic? 0
  • +

Replies To: Data from 2 Tables MySQL

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1002
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1