I am currently working on a project to I fetch some information from an API and store it in a database. The table structure looks something like this:
id ident aircraft_type origin destination timestamp departure_time
1 AWE1843 A321 KATL KCLT 2012-10-04 10:46:34 2012-10-04 10:01:00
2 ASQ5758 CRJ2 KATL KIAD 2012-10-04 10:51:11 2012-10-04 09:40:00
3 AAL2404 B738 KLAX KDFW 2012-10-04 10:46:13 2012-10-04 08:23:00
4 AAL2400 B738 KLAX KDFW 2012-10-04 09:54:13 2012-10-04 07:31:00
5 UAL912 B752 KLAX KJFK 2012-10-04 10:19:24 2012-10-04 05:39:00
6 DAL1162 B752 KLAX KCLT 2012-10-04 09:38:00 2012-10-04 04:44:30
The six rows are for demonstration purposes; I have around 500 rows of such data. The application I am working on will ask the user to provide the two origin points and will provide the user with all the common destinations between those two origins.
For example, if a user enters “KATL” and “KLAX” as origin airports, the query displays the common destination between the two origins which is “KCLT”.
I tried different approaches to fix the issue but cannot get the desired functionality achieved. I tried joins and different ActiveRecord methods to no use.
Something like this will work it will give you both tables though, you can use s.* or e.* to pick specific table if you need to:
If you just want to display destinations: