0

我有 3 张桌子

  1. User_Details 带列 ( user_id, name)
  2. Stock_Details 带列 ( user_id foreign key, stocks)
  3. Billing_Details带列 ( user_id foreign key, billing)

如何使用和显示用户Stock_Details列表billing_Details

4

3 回答 3

2
SELECT u.user_id,
       u.name,
       b.billing,
       s.stocks
FROM user_details u
LEFT JOIN billing_details b on b.user_id = u.user_id
LEFT JOIN stock_details s on s.user_id = u.user_id
于 2012-12-15T07:20:48.967 回答
1

请试试:

SELECT 
    T1.user_id,
    T1.name,
    T2.stocks,
    T3.billing
FROM
    User_Details T1 INNER JOIN Stock_Details T2 ON T1.User_id=T2.User_id
        INNER JOIN Billing_Details T3 ON T2.User_id=T3.User_id
于 2012-12-15T07:00:41.120 回答
0

如果您想显示库存表或帐单表中的记录,请尝试此...

select <your required fields> 
From User_Details ud inner join Stock_Details sd on ud.user_id=sd.user_id
Union 
select <your required fields> 
From User_Details ud inner join billing_Details bd on ud.user_id=bd.user_id
where ud.user_id not in (select user_id from stock_details)

注意:字段在联合和相同的顺序中是相同的。否则它会返回错误。

于 2012-12-15T12:58:32.503 回答