4 ms·
To me this is way more readable: SELECT t.passenger_name, t.ticket_no, bp.seat_no FROM Flights f, Ticket_f
by shrx 2y ago
To me this is way more readable:
SELECT
t.passenger_name,
t.ticket_no,
bp.seat_no
FROM
Flights f,
Ticket_flights tf,
Tickets t,
Boarding_passes bp
WHERE
f.flight_id = tf.flight_id
AND f.arrival_airport = 'OVB'
AND tf.ticket_no = t.ticket_no
AND t.ticket_no = bp.ticket_no
AND tf.flight_id = bp.flight_id;
- wild_egg 2y agoNo love for JOIN ... USING in this thread eh SELECT t.passenger_name, t.ticket_no, bp.seat_no FROM Flights f JOIN Ticket_flights tf USING (flight_id), JOIN Tickets t USING (ticket_no), JOIN Boarding_pass bp USING (ticket_no, flight_id) WHERE f.arrival_airport = 'OVB';
- dhc02 2y agoI like this and haven't used it before. Thanks for sharing.
- goodlinks 2y agoNever seen this before, always thought it would be tasty sugar though.. thanks for making me aware of it!
- Suppafly 2y agoI've never seen USING before, is that available in mssql or just the various open source ones?
- santiagobasulto 2y agoFor me, idk why, it feels too "ORACLE-ly". I stopped using Oracle after administering an 9i until ~2010 and I never want to go back But yes, `USING` is convenient and pleasant to the eyes.
- yen223 2y ago`using` works really well, but only when the two column names are the same. That's why it's not a bad idea to include the table name in the id column name: `flight.flight_id` instead of `flight.id`.
- pophenat 2y agoTo me placing the join predicates immediately after the tables is more readable as I don’t have to switch between looking at the from and where clauses to figure out the columns on which the tables are joined.
- buttercraft 2y agoYep, nothing is harder to read than joins scattered in random order throughout the where clause. Additionally, putting joins in the where clause breaks the separation of concerns: FROM: specify tables and their relationships WHERE: filter rows SELECT: filter columns
- mmcdermott 2y agoI've usually found that this breaks down when there are a lot of filtering conditions besides the join condition, and multiple columns used in the joins. The WHERE clause gets long and jumbled and it is much easier to separate join conditions from filtering conditions.
- Suppafly 2y agoI guess as long as you're giving it some criteria to join on, I had a coworker do these sorts of joins but never specified any real criteria for joining and the queries were always a mess and returned tons of extra junk. Personally I prefer to explicitly do the joins first.