I have a database with a many to many relation ...
table REFERENCE contains data about library items
table TOPIC contains the topics covered by these items
table REFERENCE_TOPIC contains the relation between the items in both tables.
suppose i want all the fields from the table REFERENCE but only where the topic is a certain value (i'm doing an ASP page, so it the querystring passed by the page)
would this select statement do the job?
"SELECT * FROM REFERENCE WHERE ([REFERENCE_TOPIC].ref_id=[REFERENCE].ref_id AND [REFERENCE_TOPIC].topic_id=" & Request.QueryString("topic_id")
i'm gonaa try ... hope to get some feed backThere are many methods to accomplish this.
1)
Select R.*
From REFERENCE R
INNER JOIN
REFERENCE_TOPIC RT
ON R.ID = RT.R_ID
INNER JOIN
TOPIC T ON
T.ID = RT.T_ID AND T.value = 'x'
2)
Select R.*
From REFERENCE R
where R.ID IN
(Select RT.R_ID
From REFERENCE_TOPIC RT
Where RT.T_ID IN
(Select T.ID
From TOPIC T
Where T.value ='X'))
No comments:
Post a Comment