简体   繁体   中英

Using LIKE in a join statement

I need to form a select statement to filter the table from my artists table with all the artists that start with the letter 'Q' and their respective songs.

Artist table columns: artist_id, name.
Song table columns: song_id, title, minutes, seconds, genre_id.
song_artist columns(junction): song_id, artist_id;

Consider:

select a.*, s.*
from artist a
inner join song_artist sa on sa.artist_id = a.artist_id
inner join song s on s.song_id = sa.song_id
where a.name like 'Q%'

Try this code:

select * from Artists t1
left outer join Song_Artist t2 on t1.Artist_ID=t2.ArtistID
left outer join Songs t3 on t2.SongID=t3.Song_Id
where t1.ArtistName like 'Q%'

Pretty basic.

...where artists like 'Q%'...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM