Solved

Help required writing join query

Posted on 2013-05-23
1
247 Views
Last Modified: 2013-06-08
I need to get name(of a collection) from Table1 and name of all the songs in that collection from table 3 . Table 2 is the connection between table 1 and table 3. music_playlist_id connects table 2 to table 1. tbl_content_common_id connects table 2 with table 3.

Table 1

CREATE TABLE IF NOT EXISTS `music_playlists` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `collection_id` int(10) NOT NULL,
  PRIMARY KEY (`id`)
)

Open in new window


Table 2

CREATE TABLE IF NOT EXISTS `playlist_song_mappings` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `music_playlist_id` int(11) NOT NULL,
  `tbl_content_common_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)

Open in new window



Table 3

CREATE TABLE IF NOT EXISTS `tbl_content_commons` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `content_common_code` varchar(20) CHARACTER SET utf8 NOT NULL,
  `content_common_name` varchar(100) CHARACTER SET utf8 NOT NULL
)

Open in new window


Any help is much appreciated
0
Comment
Question by:Sreejith22
1 Comment
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 250 total points
ID: 39190506
SELECT m.[name] AS CollectionName, c.content_common_name
FROM music_playlists m INNER JOIN
    playlist_song_mappings p ON m.collection_id = p.music_playlist_id INNER JOIN
    tbl_content_commons c ON p.tbl_content_common_id = c.id
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question