/ Forside / Teknologi / Udvikling / SQL / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
SQL
#NavnPoint
pmbruun 1704
niller 962
fehaar 730
Interkril.. 701
ellebye 510
pawel 510
rpje 405
pete 350
gibson 320
10  smorch 260
problems with getting the right data ?
Fra : EnjoyNews


Dato : 08-02-06 12:52

I have some tables that is connected in a table like this:

TracklistID
CDid
SongID

it could look like this


1 1 1
2 1 2
3 1 3
4 1 4
5 2 3
6 2 4
7 2 5
8 3 4

So CD 1 has the four tracks 1,2,3 and 4
CD 2 has three tracks 2,4 and 6
and CD 3 has the one track 4

Then I can list the albums that contains track 3 very simple ofcause by typr
WHERE SongID='3'

But now I want to do a search on which albums contains to different songs.
Ex. which albums contain track 3 and 4
If I type WHERE SongID='3' AND SongID='4' it doesn't work because no posts
has two songid's ofcause.
And if I type WHERE SongID='3' OR SongID='4' it doesn't work because it then
includes CD 3 because it has one of the tracks.

So how do I get it to list the CD's that has both track 3 and 4 in it ??


best
Michael



 
 
Kristian Damm Jensen (09-02-2006)
Kommentar
Fra : Kristian Damm Jensen


Dato : 09-02-06 13:16

EnjoyNews wrote:
> I have some tables that is connected in a table like this:
>
> TracklistID
> CDid
> SongID
>
> it could look like this
>
>
> 1 1 1
> 2 1 2
> 3 1 3
> 4 1 4
> 5 2 3
> 6 2 4
> 7 2 5
> 8 3 4
>
> So CD 1 has the four tracks 1,2,3 and 4
> CD 2 has three tracks 2,4 and 6
> and CD 3 has the one track 4
>
> Then I can list the albums that contains track 3 very simple ofcause
> by typr WHERE SongID='3'
>
> But now I want to do a search on which albums contains to different
> songs. Ex. which albums contain track 3 and 4
> If I type WHERE SongID='3' AND SongID='4' it doesn't work because no
> posts has two songid's ofcause.
> And if I type WHERE SongID='3' OR SongID='4' it doesn't work because
> it then includes CD 3 because it has one of the tracks.
>
> So how do I get it to list the CD's that has both track 3 and 4 in it
> ??
>
>
> best
> Michael

select *
from songs s1
join songs w2
on s1.cdID = s2.cdID
where s1.songID = 3
and s2.songID = 4

P.S. Hvorfor skrive på engelsk i en dansk gruppe?


--
Kristian Damm Jensen



EnjoyNews (10-02-2006)
Kommentar
Fra : EnjoyNews


Dato : 10-02-06 00:08


"Kristian Damm Jensen" <kristiandammNO@SPAMyahoo.dk> skrev i en meddelelse
news:43eba89a$0$78284$157c6196@dreader1.cybercity.dk...
> EnjoyNews wrote:
> > I have some tables that is connected in a table like this:
> >
> > TracklistID
> > CDid
> > SongID
> >
> > it could look like this
> >
> >
> > 1 1 1
> > 2 1 2
> > 3 1 3
> > 4 1 4
> > 5 2 3
> > 6 2 4
> > 7 2 5
> > 8 3 4
> >
> > So CD 1 has the four tracks 1,2,3 and 4
> > CD 2 has three tracks 2,4 and 6
> > and CD 3 has the one track 4
> >
> > Then I can list the albums that contains track 3 very simple ofcause
> > by typr WHERE SongID='3'
> >
> > But now I want to do a search on which albums contains to different
> > songs. Ex. which albums contain track 3 and 4
> > If I type WHERE SongID='3' AND SongID='4' it doesn't work because no
> > posts has two songid's ofcause.
> > And if I type WHERE SongID='3' OR SongID='4' it doesn't work because
> > it then includes CD 3 because it has one of the tracks.
> >
> > So how do I get it to list the CD's that has both track 3 and 4 in it
> > ??
> >
> >
> > best
> > Michael
>
> select *
> from songs s1
> join songs w2
> on s1.cdID = s2.cdID
> where s1.songID = 3
> and s2.songID = 4
>
> P.S. Hvorfor skrive på engelsk i en dansk gruppe?
>
>
> --
> Kristian Damm Jensen


Super det virker.. mange mange tak..
Nu kan jeg sove igen

Undskyld den blev på engelsk.
Det var fordi jeg lige havde postet den på et engelsk forum, hvor der ikke
blev svaret.
Så synes jeg ikke lige jeg gad oversætte den. Jeg tænkte at I nok kunne
engelsk.



Søg
Reklame
Statistik
Spørgsmål : 177580
Tips : 31968
Nyheder : 719565
Indlæg : 6409079
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste