我有 3 张桌子
User_Details
带列 (user_id, name
)Stock_Details
带列 (user_id foreign key, stocks
)Billing_Details
带列 (user_id foreign key, billing
)
如何使用和显示用户Stock_Details
列表billing_Details
?
我有 3 张桌子
User_Details
带列 ( user_id, name
)Stock_Details
带列 ( user_id foreign key, stocks
)Billing_Details
带列 ( user_id foreign key, billing
)如何使用和显示用户Stock_Details
列表billing_Details
?
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
请试试:
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
如果您想显示库存表或帐单表中的记录,请尝试此...
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)
注意:字段在联合和相同的顺序中是相同的。否则它会返回错误。