1

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

  • 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

2
  • [Close] It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. Commented Nov 19, 2011 at 15:22
  • @MichaelDurrant I agree it was a bit vague/difficult to understand, but I have hope for this question. The diagram (hopefully) helped me to decipher it. Commented Nov 19, 2011 at 15:33

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

yes that's the answer i asked.. Any links for join's tutorial available? I take 9/10 in this lesson to my university but long time ago.. :(
I have posted a link to the MySQL join documentation, as well as a good article (with pictures) about joins. If you do not like these, or want more information, just google mysql join tutorial

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.