[英]How to add the id of the first table to the id_position field of the second table when I click submit?
[英]How to get the first table where i know the id from second table
我需要获取两个表,这是表结构
我想获取表a的数据并在tblA.IntroCode = tblB.IntroCode上与表b联接,然后获取tblB.userID的用户名。 我该如何加入?
我尝试了一半,卡在中间,请帮忙。 谢谢您的回复
这只是一个简单的连接。
SELECT a.*, b.* -- select your desired columns here
FROM tableA a
INNER JOIN tableB b
ON a.IntroCode = b.IntroCode
WHERE b.userid = valueHere
更新1
SELECT a.UserID,
a.`Username` OrigUserName,
a.`Status`,
c.`Username` IntroUserName
FROM tableA a
INNER JOIN tableB b
ON a.IntroCode = b.IntroCode
INNER JOIN tableA c
ON b.userID = c.userID
-- WHERE b.UserID = valueHere -- extra condition here
SELECT column_name(s)
FROM TableA
LEFT JOIN TableB
ON TableA.UserID=TableB.UserID
SELECT B.userID from TableA A
LEFT JOIN TableB B on A.IntroCode=B.IntroCode
select a.*,b.IntroCode from TableA a left join TableB b
on a.IntroCode = b.IntroCode
您必须为具有相同名称的列赋予唯一值:
SELECT a.UserID as uid_a, b.UserID as uid_b
FROM tableA a
INNER JOIN tableB b ON a.IntroCode = b.IntroCode
WHERE b.UserID = 1
使用此查询。
SELECT TableA.Username FROM TableA JOIN TableB ON (TableA.IntroCode = TableB.IntroCode);
使用此查询
SELECT * FROM tblA INNER JOIN tblB ON tblA.IntroCode = tblB.IntroCode where tblB.userid = value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.