SQL help - trying to do a 3 table join

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   SQL help - trying to do a 3 table join
mearnheart
CZ Newbie
mearnheart has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 29, 2005
0.00 posts per day
Posts: 6
Points: 261
   
ok, here goes....

Table employee has columns id, name
Table ticket has columns id, emp_id, cust_id, office, issue_date
Table customer has columns id, name

here is what I'm trying to do:
SELECT *
FROM ticket.a, employee.b, customer.c
WHERE a.office = 'Dallas'
AND a.cust_id = 75
AND a.emp_id = b.id
AND a.cust_id = c.id
AND a.emp_id = 144 OR a.emp_id = 18
ORDER BY a.tech_id, a.cust_id, a.issue_date

yea, I think that should do what I need......

its returning like 136,000+ records....and I'm pretty sure thats not right.....theres only ll records in ticket, 74 records in customers, and 205 in employee.....

TIA,
Mike



Back to top Reply with quote
#2   re: SQL help - trying to do a 3 table join
Kelly_Hero
PayPal Donation
CZ Revered Member
 Codezwiz Site Donator
Kelly_Hero has been a member for over 20 year's 20 Year Member
usa.gif southcarolina.gif
Occupation: Web Developer
Age: 58
Gender: Female
Website:
Status: Offline
Joined: Aug 20, 2003
0.50 posts per day
Posts: 3765
Points: 351,412
   
Instead of ticket.a, employee.b and customer.c, try ticket AS a, employee AS b, customer AS c.

You are also trying to order by a.tech_id, but you don't have a field listed as tech_id in the ticket table.

That may not solve the whole problem, but it should get you a little closer, I hope.



Back to top Reply with quote
#3   re: SQL help - trying to do a 3 table join
minirich
CZ Newbie
minirich has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Sep 26, 2005
0.00 posts per day
Posts: 1
Points: 20
   
It has nothing to do with the ordering its because you have

select * from ....
you get for every table and every row in that table and their combinations a result row
you have to do
select ticket.* from ...
or another table prefix to limit the result count.



Back to top Reply with quote
#4   re: SQL help - trying to do a 3 table join
mearnheart
CZ Newbie
mearnheart has been a member for over 18 year's 18 Year Member
Gender: Male
Status: Offline
Joined: Jul 29, 2005
0.00 posts per day
Posts: 6
Points: 261
   
yes, thank you very much.....

mike



Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum