Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help required writing join query

Posted on 2013-05-23
1
Medium Priority
?
256 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 93

Accepted Solution

by:
Patrick Matthews earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

885 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