[英]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.