Java 學習記錄113 — More Complex Joins

張小雄
2 min readJan 29, 2022

--

接續 112 — SQL Order by and Joins

輸入:SELECT albums.name, songs.track, songs.title FROM songs INNER JOIN albums ON songs.album = albums._id ORDER BY albums.name, songs.track

輸出:

(略刪)

heavens to betsy|7|A Hundred Years Ago

heavens to betsy|8|The Belgian Tune

whip Jamboree|1|The Valiant Turpin

whip Jamboree|2|Devil in the Kitchen

whip Jamboree|3|Ford O’ Kabul River

whip Jamboree|4|Bulgine

whip Jamboree|5|The New Jigs

whip Jamboree|6|Lankin

whip Jamboree|7|Polka Against the Clock

whip Jamboree|8|Rackabella

whip Jamboree|9|The Four Hour Shovel

whip Jamboree|10|Landlady

whip Jamboree|11|Whitstable Cottage-Superfly

whip Jamboree|12|Whip Jamboree

最左邊是專輯名,按專輯跟歌曲順序排序,第幾首歌的歌名是啥

輸入: SELECT artists.name, albums.name FROM albums INNER JOIN artists ON albums.artist = artists._id ORDER BY artists.name;

輸出:

(略刪)

Warner E Hodges|Gunslinger

White Zombie|Astro-Creep

Wishbone Ash|Argus

Wishbone Ash|Keeper Of The Light [Live In Chicago]

Wishbone Ash|Wishbone Four

Yardbirds|The Very Best of the Yardbirds

Yngwie Malmsteen|Rising Force

ZZ Top|Rio Grande Mud

ZZ Top|Antenna

ZZ Top|Recycler

ZZ Top|Mescalero

ZZ Top|Tres Hombres

ZZ Top|Deguello

把歌手出過的專輯,按歌手名稱排序

輸入:

SELECT artists.name, albums.name, songs.track, songs.title FROM songsINNER JOIN albums ON songs.album = albums._idINNER JOIN artists ON albums.artist = artists._idORDER BY artists.name, albums.name, songs.track;

輸出:

(略刪)

ZZ Top|Rio Grande Mud|8|Sure Got Cold After The Rain Fell

ZZ Top|Rio Grande Mud|9|Whiskey’n Mama

ZZ Top|Rio Grande Mud|10|Down Brownie

ZZ Top|Tres Hombres|1|Waitin’ For The Bus

ZZ Top|Tres Hombres|2|Jesus Just Left Chicago

ZZ Top|Tres Hombres|3|Beer Drinkers & Hell Raisers

ZZ Top|Tres Hombres|4|Master Of Sparks

ZZ Top|Tres Hombres|5|Hot Blue And Righteous

ZZ Top|Tres Hombres|6|Move Me On Down The Line

ZZ Top|Tres Hombres|7|Precious And Grace

ZZ Top|Tres Hombres|8|La Grange

ZZ Top|Tres Hombres|9|Sheik

ZZ Top|Tres Hombres|10|Have You Heard

ZZ Top|Tres Hombres|11|Waitin’ For The Bus (Live) (Bonus)

ZZ Top|Tres Hombres|12|Jesus Just Left Chicago (Live) (Bonus)

ZZ Top|Tres Hombres|13|La Grange (Live) (Bonus)

把三張表都串在一起了,所以有兩次 JOIN ,最後一行就排順序

剛看會被嚇到,一行一行拆開來看就好

--

--

張小雄
張小雄

Written by 張小雄

記錄成為軟體工程師的過程

No responses yet