Hi, i have a main table that stores lookup values to other tables such as customer, car etc...
however one lookup table is a many-to-many relationship so it uses a link table called stdworklink but even though the link table has two foreign key records from the main table my query displays only one result.
do i need to use a nested query - have started but is still only get one result, any ideas welcome
however one lookup table is a many-to-many relationship so it uses a link table called stdworklink but even though the link table has two foreign key records from the main table my query displays only one result.
do i need to use a nested query - have started but is still only get one result, any ideas welcome
Code:
SELECT mot.mott, book.carid, car.reg, car.modelid, make.make, users.user, book.bookid, book.bookdate,
book.waittick, book.booknotes, cus.fname, cus.lname, cus.pcode, cus.add1, cus.hphone, cus.wphone,
cus.mphone, cus.cusid, mot.bayid, mot.motid, mot.dayid, mot.baytypeid, book.oldcar, SLL.stdworkid
FROM mottimes AS mot
LEFT JOIN book ON mot.motid = book.slotid AND book.bookdate = 20070928
LEFT JOIN car ON car.carid = book.carid
LEFT JOIN cus ON cus.cusid = car.cusid
LEFT JOIN make ON make.makeid = car.makeid
LEFT JOIN users ON users.userid = book.userid
LEFT JOIN
(SELECT SL.stdworkid, SL.bookid FROM stdworklink AS SL)
AS SLL
ON book.bookid = SLL.bookid
WHERE mot.dayid =1 AND ((mot.bayid = 1 AND mot.baytypeid =2)
or (mot.bayid = 2 AND mot.baytypeid =2))
GROUP BY mot.motid
ORDER BY mot.motid, mot.mott, mot.bayid, mot.baytypeid