Big_Pat Posted May 28, 2013 Share Posted May 28, 2013 So what songs in my collection are cover versions of Bob Dylan songs? I wrote this query to find out: $query = "Select artist from songlist where title in (Select distinct title from songlist where artist='Bob Dylan')"; but running it times out. If I substitute the inner select for a simple list of, say, three or four of his songs, the query runs fine so I can only assume that the thousands of permutations are what's slowing things down. Is there a more efficient way of achieving the same thing? Ultimately I'd like to replace 'Bob Dylan' with a variable, but first things first. Thanks! Link to comment https://forums.phpfreaks.com/topic/278466-mysql-select-within-select-taking-forever/ Share on other sites More sharing options...
jazzman1 Posted May 28, 2013 Share Posted May 28, 2013 With this database design (we were talking about before) I think, it's the best you can do. Link to comment https://forums.phpfreaks.com/topic/278466-mysql-select-within-select-taking-forever/#findComment-1432711 Share on other sites More sharing options...
Barand Posted May 28, 2013 Share Posted May 28, 2013 try a JOIN Select artist from songlist inner join (Select distinct title from songlist where artist='Bob Dylan') as dylan using (title) Link to comment https://forums.phpfreaks.com/topic/278466-mysql-select-within-select-taking-forever/#findComment-1432712 Share on other sites More sharing options...
Big_Pat Posted May 28, 2013 Author Share Posted May 28, 2013 Thank you, Barry, that's worked a charm. Why does yours work and mine doesn't? Link to comment https://forums.phpfreaks.com/topic/278466-mysql-select-within-select-taking-forever/#findComment-1432718 Share on other sites More sharing options...
Barand Posted May 28, 2013 Share Posted May 28, 2013 Efficiency. One table subquery called once versus a dependent subquery called for every row Link to comment https://forums.phpfreaks.com/topic/278466-mysql-select-within-select-taking-forever/#findComment-1432726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.