Quantcast
Channel: How to fix SELECT statement to return duplicates - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How to fix SELECT statement to return duplicates

$
0
0

Currently I am trying to return a three table join to find duplicate track titles that are in my a "track" table, and also return the track number | cd title from the other joined tables. My select statement is currently returning all the information from the joined tables but its not showing only the duplicates.

I have also tried using a group by and having clause to try to find a COUNT of comptitle. When I tried that it returned the an empty table.

My Tables:

CREATE TABLE composition (compid, comptitle,...,    PRIMARY KEY (compid),...);CREATE TABLE recording (rcdid,..., compid,    PRIMARY KEY (rcdid, compid),...);CREATE TABLE cd (cdid, cdtitle,...,     PRIMARY KEY(cdid),...);CREATE TABLE track (cdid, trknum,..., rcdid, compid,    PRIMARY KEY (cdid, trknum),...);

My statement:

SELECT comptitle, trknum, cdtitle    FROM track JOIN recording ON track.rcdid = recording.rcdid    JOIN composition ON recording.compid = composition.compid    JOIN cd ON cd.cdid = track.cdid;

Output expected | actual:

EXPECTED:      comptitle      | trknum | cdtitle     -------------------------------------------- Cousin Mary         | 2      | Giant Steps  Cousin Mary         | 10     | Giant Steps  Giant Steps         | 1      | Giant Steps  Giant Steps         | 8      | Giant Steps ACTUAL:         comptitle          | trknum |   cdtitle   ----------------------------+--------+------------- Giant Steps                | 8      | Giant Steps Giant Steps                | 1      | Giant Steps Stomp of King Porter       | 1      | Swing Sing a Study in Brown      | 2      | Swing Cousin Mary                | 14     | Swing Cousin Mary                | 10     | Giant Steps

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images