Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Unanswered: SQL multi-table query

    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

  2. #2
    Join Date
    Nov 2012
    Posts
    2

    Not sure if this helps

    When this is entered I get the correct output.

    Code:
    SQL> select ic_cabnum, ic_incitype
      2  from incident
      3  where ic_wkdate = '15-NOV-2007';
    IC_ IC_INCITYPE
    --- ---------------
    215 TICKET
    215 TICKET
    215 TICKET
    144 TICKET
    144 TICKET
    144 TICKET
    455 TICKET

    I need to display the names of the drivers, but none of the information in the driver table is also in the incident table. So from what we've learned so far I must join a table with similar data from the driver table and the incident table (which is in the shift table)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •