Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

SQL multi-table query

$
0
0
I'm having some issues getting the correct outcome for this query. When I enter this code :
Code:

1        SQL> select dr_drvname, ic_cabnum, ic_incitype
2        2  from (driver JOIN shift ON sh_drvnum = dr_drvnum) JOIN incident  ON ic_wkdate = sh_wkdate
3        3  where ic_wkdate = '15-NOV-2007'
4        4  order by dr_drvnum;

I get the correct selections but I am getting multiples for each incident type. If i do just the information from the incident table I get the correct return, the problem only happens when I do the joins.
I've tried LEFT JOIN and DISTINCT, but to no avail. The outcome I'm getting looks like this:

DR_DRVNAME IC_ IC_INCITYPE
------------------------------ --- ------------
Pettit, R. Richardson 215 TICKET
Pettit, R. Richardson 144 TICKET
Pettit, R. Richardson 144 TICKET
Pettit, R. Richardson 144 TICKET
Pettit, R. Richardson 455 TICKET
Hickman, Ronald S. 215 TICKET
Hickman, Ronald S. 215 TICKET
Hickman, Ronald S. 215 TICKET
Hickman, Ronald S. 144 TICKET
Hickman, Ronald S. 144 TICKET
Hickman, Ronald S. 144 TICKET

But it should only return 6 results. Any help would be amazing!
Thanks

Viewing all articles
Browse latest Browse all 13329

Trending Articles