简体   繁体   中英

SQL Server: one simple question

So I have a table Transportation with columns: ClientIDAsSeller, ClientIDAsBuyer ..

and a Client table with column ID (Primary key). My C# app gets a client IDs and sets in the Transportation table.

When I press execute result is null

What is problem how can I solve that?

SELECT     
   Clients.Name, Transportation.TransStart, Transportation.TransEnd
FROM         
   Transportation 
INNER JOIN
   Clients ON Transportation.ClientIDAsSeller = Clients.ID 
              AND Transportation.ClientIDAsBuyer = Clients.ID

You are likely excluding all possible result sets by only doing one join. You probably want to do:

SELECT
      S.Name as SellerName
      B.Name as BuyerName,
      Transportation.TransStart,
      Transportation.TransEnd
FROM Transportation
INNER JOIN
     Clients S
ON
     Transportation.ClientIDAsSeller = S.ID
INNER JOIN
     Clients B
ON
     Transportation.ClientIDAsBuyer = B.ID

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM