Ok, so I have an organization id column named org_id in several databases.
I am writing a search function that will query two of these databases, and look for all org_id’s associated with a value in these two tables.
I ONLY want to ultimately have the org_id’s that correspond with the values I am querying for in EACH table.
For example:
Say I have an org_id of 3 that is in the tables cult_xref and cat_xref, which are both associated with an organization table, which isn’t really relevant for this. I want to ONLY pull those org_id’s which are in BOTH tables cult_xref and cat_xref, based on values I put into those tables, say 2 and 6 respectively.
So:
cult_xref
org_id | cult_id
3 | 2
4 | 2
3 | 5
and
cat_xref
org_id | cat_id
3 | 6
3 | 1
7 | 6
I would only want to pull the org_id’s that fulfill cult_id[‘2’] and cat_id[‘6’] at the SAME TIME.
In SQL, this is called a JOIN.
For a nice introduction to joins, see A Visual Explanation of SQL Joins