#1066 - Not unique table/alias: 'clients' I have Problem:


  #1066 - Not unique table/alias: 'clients'


SELECT request.*, 
       clients.ClientName AS ToClient, 
       clients.ClientName AS FromClient, 
       drivers.DriName, requesttype.ReqTName 
FROM request
    INNER JOIN clients ON clients.ClientID = request.ReqToClient
    INNER JOIN clients ON clients.ClientID = request.ReqFromClient
    INNER JOIN drivers ON drivers.DriID = request.DriID
    INNER JOIN requesttype ON requesttype.ReqTID = request.ReqTID
You joined clients twice in the same FROM clause, that's throwing the error.

The two incarnations of the table need to have different aliases (chosen: cl_to and cl_from):

SELECT request.*, 
       cl_to  .ClientName AS ToClient, 
       cl_from.ClientName AS FromClient, 
       drivers.DriName, requesttype.ReqTName 
FROM request
    INNER JOIN clients AS cl_to    -- alias 1 
        ON cl_to.ClientID = request.ReqToClient
    INNER JOIN clients AS cl_from   -- alias 2
        ON cl_from.ClientID = request.ReqFromClient
    INNER JOIN drivers
        ON drivers.DriID = request.DriID
    INNER JOIN requesttype
        ON requesttype.ReqTID = request.ReqTID ;


I'd prefer to use (short) aliases for all tables:

SELECT rq.*, 
       cl_to  .ClientName AS ToClient, 
       cl_from.ClientName AS FromClient, 
       dr.DriName, rt.ReqTName 
FROM request AS rq
    INNER JOIN clients AS cl_to   ON cl_to.ClientID = rq.ReqToClient
    INNER JOIN clients AS cl_from ON cl_from.ClientID = rq.ReqFromClient
    INNER JOIN drivers AS dr      ON dr.DriID = rq.DriID
    INNER JOIN requesttype AS rt  ON rt.ReqTID = rq.ReqTID ;