sql - Joining tables in MySQL with multiple foreign keys -
i have 2 tables
rides (from 1 point another)+------+-------+-------+-------+-------+ | id | start | end | pointa| pointb| +------+-------+-------+-------+-------+ | 1 | xxx | xx | 1 | 2 | | 2 | xxx | xx | 2 | 1 | +------+-------+-------+-------+-------+
points +------+-------------+ | id | desc | +------+-------------+ | 1 | "chicago" | | 2 | "nyc" | +------+-------------+
so example:
when person rides point point b gets registerd in rides
table. pointa
, pointb
both fk's in rides
table table points
how possible sql output in mysql
ride id = 1
example:
+------+-------+-------+-------+-------+ | id | start | end | pointa| pointb| +------+-------+-------+-------+-------+ | 1 | xxx | xx |chicago| nyc |
you can bring together same table twice, giving each 1 different alias:
select r.id, r.start, r.end, pa.desc pointa, pb.desc pointb rides r bring together points pa on pa.id = r.pointa bring together points pb on pb.id = r.pointb r.id = 1;
mysql sql
No comments:
Post a Comment