what column ties the two tables together?
A JOIN will accomplish this if there is a relationship.
Example:
SELECT history_overall.* FROM members
JOIN history_overall
ON history_overall.member_id = members.id
WHERE members.active = 'Y';
----Edit/Comment----
Since I'm not able to add the table structure layout in a comment I will comment here.
It is more valuable when wanting to retrieve specific records from the database to provide us with the table schema as opposed to the actual table names. As well as an example of the resulting data you want as a result.
All you really provided to us with is table history_2014
with columns (member
= Y|N
), table history_overall
with columns (address1, last_name
) which doesn't allow us to build a relationship between the two (or more) tables.
Here is an example assuming both tables have a memberid column:
----------------------- -------------------------------------
| table1 | | table2 |
----------------------- -------------------------------------
| member | memberid | | address1 | full_name | memberid |
----------------------- -------------------------------------
| Y | 1 | | 123 street | jon doe | 1 |
----------------------- -------------------------------------
| N | 2 | | 789 court | jane doe | 2 |
----------------------- -------------------------------------
| Y | 3 | | 456 road | foo bar | 3 |
----------------------- -------------------------------------
Question: How can I retrieve records from table2 where the member in table1 is 'Y'?
This is my desired result of the records:
-------------------------------------
| recordset |
-------------------------------------
| address1 | full_name | memberid |
-------------------------------------
| 123 street | jon doe | 1 |
-------------------------------------
| 456 road | foo bar | 3 |
-------------------------------------
Answer query:
SELECT table2.*
FROM table1
JOIN table2
ON table1.memberid = table2.memberid
WHERE table1.member = 'Y'
Explained:
Retrieve all columns in table2 that the memberid column in table1 is the same as the memberid column in table2 from the rows in table1 that the member column contains Y as a value with no ordering or limit on the amount of records returned.