happykiran
Programmer
Hi,
I got these two tables in the database. Now I want the output from activity_log. The cfrom and cto refer to routeid in 'routeprefix' table. If I want to view the names of the routes instead of their IDs in the activity table, how should I frame my SQL statement ?
mysql> select * from activity_log;
+----+-------+---------------------+-------+-----+
| id | user | action_date | cfrom | cto |
+----+-------+---------------------+-------+-----+
| 56 | Kiran | 2004-05-03 22:48:25 | 2 | 1 |
| 57 | Kiran | 2004-05-03 22:48:25 | 2 | 1 |
| 58 | Kiran | 2004-05-03 22:48:25 | 2 | 1 |
| 59 | Kiran | 2004-05-04 12:02:25 | 2 | 2 |
| 60 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 61 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 62 | Kiran | 2004-05-05 11:58:45 | 1 | 4 |
| 63 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 64 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 65 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
+----+-------+---------------------+-------+-----+
mysql> select * from routeprefix;
+---------+-----------+--------+
| routeid | route | prefix |
+---------+-----------+--------+
| 1 | A | 00 |
| 2 | B | 54 |
| 3 | C | 11 |
| 4 | D | 12 |
+---------+-----------+--------+
expected output
---------------
+----+-------+---------------------+-------+-----+
| id | user | action_date | cfrom | cto |
+----+-------+---------------------+-------+-----+
| 56 | Kiran | 2004-05-03 22:48:25 | B | A |
| 57 | Kiran | 2004-05-03 22:48:25 | B | A |
| 58 | Kiran | 2004-05-03 22:48:25 | B | A |
| 59 | Kiran | 2004-05-04 12:02:25 | B | B |
| 60 | Kiran | 2004-05-05 11:58:45 | B | D |
| 61 | Kiran | 2004-05-05 11:58:45 | B | D |
| 62 | Kiran | 2004-05-05 11:58:45 | A | D |
| 63 | Kiran | 2004-05-05 11:58:45 | B | D |
| 64 | Kiran | 2004-05-05 11:58:45 | B | D |
| 65 | Kiran | 2004-05-05 11:58:45 | B | D |
+----+-------+---------------------+-------+-----+
I got these two tables in the database. Now I want the output from activity_log. The cfrom and cto refer to routeid in 'routeprefix' table. If I want to view the names of the routes instead of their IDs in the activity table, how should I frame my SQL statement ?
mysql> select * from activity_log;
+----+-------+---------------------+-------+-----+
| id | user | action_date | cfrom | cto |
+----+-------+---------------------+-------+-----+
| 56 | Kiran | 2004-05-03 22:48:25 | 2 | 1 |
| 57 | Kiran | 2004-05-03 22:48:25 | 2 | 1 |
| 58 | Kiran | 2004-05-03 22:48:25 | 2 | 1 |
| 59 | Kiran | 2004-05-04 12:02:25 | 2 | 2 |
| 60 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 61 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 62 | Kiran | 2004-05-05 11:58:45 | 1 | 4 |
| 63 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 64 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
| 65 | Kiran | 2004-05-05 11:58:45 | 2 | 4 |
+----+-------+---------------------+-------+-----+
mysql> select * from routeprefix;
+---------+-----------+--------+
| routeid | route | prefix |
+---------+-----------+--------+
| 1 | A | 00 |
| 2 | B | 54 |
| 3 | C | 11 |
| 4 | D | 12 |
+---------+-----------+--------+
expected output
---------------
+----+-------+---------------------+-------+-----+
| id | user | action_date | cfrom | cto |
+----+-------+---------------------+-------+-----+
| 56 | Kiran | 2004-05-03 22:48:25 | B | A |
| 57 | Kiran | 2004-05-03 22:48:25 | B | A |
| 58 | Kiran | 2004-05-03 22:48:25 | B | A |
| 59 | Kiran | 2004-05-04 12:02:25 | B | B |
| 60 | Kiran | 2004-05-05 11:58:45 | B | D |
| 61 | Kiran | 2004-05-05 11:58:45 | B | D |
| 62 | Kiran | 2004-05-05 11:58:45 | A | D |
| 63 | Kiran | 2004-05-05 11:58:45 | B | D |
| 64 | Kiran | 2004-05-05 11:58:45 | B | D |
| 65 | Kiran | 2004-05-05 11:58:45 | B | D |
+----+-------+---------------------+-------+-----+