Go Back   SitePoint Forums > Forum Index > Program Your Site > Databases > MySQL
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old Aug 5, 2005, 13:26   #1
vinyl-junkie
$this->toCD-R(LP);
 
vinyl-junkie's Avatar
 
Join Date: Dec 2003
Location: Federal Way, Washington (USA)
Posts: 1,627
Help needed with this SQL statement

I've got one last piece to this SQL statement that I can't quite figure out. I'm trying to do a union between three tables with the following characteristics.

tblArtists - one to many
tblAlbums - each Artist can have one to many albums
tblTracks - each Album can have one to many tracks

What I want to do is list data by Artist and Album, where the lyrics id for an album track is a certain value.

The following query works, but with the literal Where value just as you see it here (bolded for emphasis). I want to know what the Where clause should really look like.

Thanks in advance for your help.

Code:
(
SELECT 
tblAlbums.Title AS albumtitle
, tblAlbums.TitleSort
, tblAlbums.MediaType AS format
, tblAlbums.AlbumID AS albumid
, tblArtists.The AS artist_the
, tblArtists.Artist AS artist
, tblArtists.ArtistID AS artistid
, tblArtists.SortName AS sortname
FROM tblArtists
INNER JOIN tblAlbums ON tblArtists.ArtistID = tblAlbums.ArtistID
WHERE tblArtists.Artist LIKE '%" . $this->where . "%'
)
UNION (

SELECT 
tblAlbums.Title
, tblAlbums.TitleSort
, tblAlbums.MediaType
, tblAlbums.AlbumID
, tblArtists.The
, tblArtists.Artist
, tblArtists.ArtistID
, tblArtists.SortName
FROM tblTracks
INNER JOIN tblAlbums ON tblTracks.AlbumID = tblAlbums.AlbumID
INNER JOIN tblArtists ON tblAlbums.ArtistID = tblArtists.ArtistID
WHERE tblTracks.Lyrics =30
)
ORDER BY sortname, albumtitle
vinyl-junkie is offline   Reply With Quote
 

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Sponsored Links
 
Forum Jump


All times are GMT -7. The time now is 03:58.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved