INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

SQL JOIN several tables help required

SQL JOIN several tables help required

(OP)
Hi guys,

I've so far had no luck getting help or solving this on my own! I have four tables which I need to join together. They are

CODE

METRICS
========
metricID    processID    name

---
R3451        1.01        Metric1
R7764        1.01        Metric2
R0443        1.01        metric3
---


METRICS_CUSTOM_REPORT
=====================
metricID    processID    orgID

---
R3451        1.01        mydemo
R7764        1.01        mydemo
---

METRICS_CALCULATED_ANSWERS
==========================
metricID    processID    answer    year

---
R3451        1.01        12.34    2007
R7764        1.01        114.55    2007
---



METRICANSWERS
=============
metricID    orgID    target    year

---
R3451        mydemo    13.00    2007
---

SO - I need ALL the records from the METRICS_CUSTOM_REPORT table based on the processID, then I need to look up the name from METRICS table. I then need ANY records in the METRICS_CALCULATED_ANSWERS and METRICANSWERS table (IF they exists). There will ALWAYS be a record in METRICS which matches the ID number from METRICS_CUSTOM_REPORT table.

Here's what I have so far - but I cannot get in the metricanswers table. What am I doing wrong?

CODE

SELECT
m.*,
c.*,
mca.*
FROM metrics_custom_report c
LEFT JOIN metrics m ON c.metricID = m.metricID
LEFT JOIN metric_calculated_answers mca ON mca.metricID = c.metricID
WHERE c.orgID='$orgID' AND
c.processID='$processID' AND
c.orgID='$orgID' AND
m.processID='$processID' AND
mca.processID='$processID' AND mca.orgID='$orgID' AND mca.year='$year'
GROUP BY m.metricID

Thanks for any help.

RE: SQL JOIN several tables help required

You might something like the following:

SELECT    C.*, M.name
FROM      metrics_custom_report C, metrics M
LEFT JOIN metric_calculated_answers A ON A.processID = C.processID
LEFT JOIN metricanswers W ON W.metricid = C.metricid
WHERE     C.metricid = M.metricid
GROUP BY  C.metricid
ORDER BY  C.metricid

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close