I’m pretty sure that I need to be doing left outer joins on my tables, but i’m not sure if that is 100% true or the syntax to write them in mySQL.
I have this query written:
select m.mechanic_id,
m.mechanic_name,
m.city,
m.state,
count(mr.mechanic_id) as num_ratings,
round(avg(mr.quality_id),2) quality_rating
round(avg(mr.friendly_id),2) friendly_rating,
round(avg(mr.professional_id),2) professional_rating
from mechanic m, mechanic_rating mr, rating r
where m.mechanic_id in (1)
and m.mechanic_id = mr.mechanic_id
and mr.quality_id = r.rating_id(+) <-- these cause issues
and mr.friendly_id = r.rating_id(+) <-- these cause issues
and mr.professional_id = r.rating_id(+) <-- these cause issues
group by mechanic_id
The (+) are one way to do outer joins in oracle and i’m not sure how to manually write out the outer joins in this query. I’m not even sure if I have them on the right columns.
My table structure looks like this
Mechanic Table
|mechanic_id|mechanic_name|city|state|zip|
|PK |
Rating Table
|rating_id|rating |
|1 |terrible|
|2 |bad |
etc.
Mechanic_Rating table
|mechanic_rating_id|mechanic_id|quality_id|friendly_id|professional_id|
|unique auto inc |FK |
The quality_id, friendly_id, and professional_id should all be foreign keys to the rating_id in the rating table.
If i take off (+) from my query, i get zero results so i’m thinking that the problem is that i need to do left outer joins. Let me know if you need more info.
You need to learn and use the ANSI-92 Standard syntax for doing Join predicates. Using ANSI-92, your query would be written as
NOTE: What does the (1) refer to ?? Are you trying to restrict this to
where m.mechanic_id = 1 ?