|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Many-to-Many Query
Here is the setup I have:
"picture" table picID ... "picsubject" table picID subjectID "subject" table subjectID ... In this many-to-many relationship sometimes it is not necessary to list a subject with a particular picture. So I want to be able to find out how many of the pictures do not have a subject listed in the picsubject table. Is this possible with SQL? I would love to hear any suggestions. Thanks |
|
#2
|
||||
|
||||
|
Code:
SELECT A.PicID FROM picture As A INNER JOIN picSubject As B On (A.PicID = B.PicID) WHERE (B.Subject = '' OR B.Subject Is Null) |
|
#3
|
|||
|
|||
|
Quote:
Let me explain further... In the picture table I might have this: picID filename 001 test.jpeg in the subject table I might have this: subjectID subject 001 Barry Bonds So to match the information I would place into the picsubject table: picID subjectID 001 001 All the pictures may or may not have an entry in the picsubject table. It all depends on whether or not you want to specify the subject of the picture. So say I have another entry in the picture table with picID 002 and it is not entered into the picsubject table. How can I perform a query to find out that picture or any other picture is not tied to a subjectID in the picsubject table. Hopefully this makes sense. |
|
#4
|
||||
|
||||
|
Code:
SELECT * FROM picture WHERE PicID NOT IN ( SELECT DISTINCT PicID FROM PicSubject ) |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Many-to-Many Query |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|