Chris P
Chris P

Reputation: 2345

MySql join 3 tables - Multiple join

db image

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

Upvotes: 1

Views: 1142

Answers (1)

Adam Wenger
Adam Wenger

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

Related Questions