For simplicity, I will describe my problem as theoretical.
Imagine that you have two tables - MATCHES and FIGHTS. "Fighters" have a list of fighters (pk_fighter_id, fighter_name), any two of which can be planned to storm each other. Matches is probably a three-field table (pk_fight_num, fk_fighter_id1, fk_fighter_id2) that tracks these pairs. Fighter1 and Fighter2 are foreign keys that refer to entries in the Fighters table.
I need to get a list of all the fights that show who is fighting with who, i.e. "23123 | Pacquaio | Marquez". How can I structure my query for this?
I would suggest something like:
select fk_fighter_id1, fk_fighter_id2 from matches inner join fighters on matches.fk_fighter_id1=fighters.pk_fighter_id inner join fighters on matches.fk_fighter_id2=fighters.pk_fighter_id;
When I tried to mock it in Access I, it put it together, but it does not work:
SELECT matches.match_no, fighters.fighter_name, fighters.fighter_name FROM fighters INNER JOIN matches ON (fighters.fighter_id = matches.fighter2) AND (fighters.fighter_id = matches.fighter1);
So, any thoughts? I just don't know where to go from here.
source share