如何从链表上的不同表中获取 [英] How to get from different table on base of link table
问题描述
我有三个表[tbl_user,tbl_controls,tbl_link],
tbl_user
UserID
UserName
tbl_controls
C_ID
ControlName
tbl_link
lk_id
用户ID
C_ID
状态(位)
控件放在tbl_control中,并且分配控件状态放在tbl_link中,我想在网格视图中加载app控件但是相关的状态由UserID的引用标记为tick。
我是如何完成这个的。
谢谢
问候>
我尝试过:
SELECT tbl_controls。 ControlName,tbl_link.Status
FROM tbl_controls left outer JOIN
tbl_link ON tbl_controls .C_ID = tbl_link .C_ID
WHERE(tbl_link.Status IN
(SELECT Status
FROM tbl_link AS tbl_link_1
WHERE(UserID = 30)))
我不确定我是否理解你,但是。 ..试试这个:
SELECT TC.ControlName,TL.Status
FROM tbl_link AS TL
INNER JOIN tbl_user AS TU ON TL.UserID = TU.UserID
INNER JOIN tbl_controls AS TC ON TL.C_ID = TC.C_ID
WHERE TL.USerId = 30
有关详细信息,请参阅: SQL联接的可视化表示 [ ^ ]
I have three table [tbl_user, tbl_controls, tbl_link],
tbl_user
UserID
UserName
tbl_controls
C_ID
ControlName
tbl_link
lk_id
UserID
C_ID
Status (bit)
the control is placed in the tbl_control, and assign control status is placed in tbl_link, I want to load app control in a grid view but the relevant status is marked tick by the reference of UserID.
How i accomplished this.
THanks
Regards
What I have tried:
SELECT tbl_controls.ControlName, tbl_link.Status FROM tbl_controls left outer JOIN tbl_link ON tbl_controls .C_ID= tbl_link .C_ID WHERE (tbl_link.Status IN (SELECT Status FROM tbl_link AS tbl_link_1 WHERE (UserID= 30)))
I'm not sure i understand you well, but... try this:
SELECT TC.ControlName, TL.Status FROM tbl_link AS TL INNER JOIN tbl_user AS TU ON TL.UserID = TU.UserID INNER JOIN tbl_controls AS TC ON TL.C_ID = TC.C_ID WHERE TL.USerId =30
For further details, please see: Visual Representation of SQL Joins[^]
这篇关于如何从链表上的不同表中获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!