Reputation: 2345
SELECT type_files.html_embed_before
, script_files.path
, type_files.html_embed_after
FROM type_files
INNER JOIN script_files ON (type_files.type = script_files.type)
the above code gives me information for all script_files. I want to build on the query and get
script_files.id = script_match.file_id
script_matches.ap_id equal to article.head, header.head OR footer.head.
The Id for article, header, footer will be passed in
Upvotes: 1
Views: 1142
Reputation: 17540
The requirement I'm least understanding is your link from script_match to article, header, and footer. This should be what you want if I understand correctly.
SELECT tf.html_embed_before
, sf.path
, tf.html_embed_after
FROM type_files AS tf
INNER JOIN script_files AS sf ON tf.type = sf.type
INNER JOIN script_match AS sm ON sf.Id = sm.file_id
WHERE sm.ap_id IN
(
SELECT a.head
FROM article AS a
WHERE a.id = @yourId
UNION ALL
SELECT h.head
FROM header AS h
WHERE h.id = @yourId
UNION ALL
SELECT f.head
FROM footer AS f
WHERE f.id = @yourId
)
MySQL JOIN documentation
Jeff Atwood's Coding Horror article on Joins
Upvotes: 1