简体   繁体   English

如何将一个表中的Id与另一个表相关联

[英]How to link Id from one table with another

i have spent the last 2 days going over this problem trying to work it out. 我花了最近两天的时间来解决这个问题,试图解决这个问题。

i have two tables 我有两张桌子

one is the user_login and it has a row called user_id the other is agedcare and it has a row called id 一个是user_login,它有一行名为user_id,另一行是agingcare,它有一行名为id

i have tried to get the 2 to link together 我试图将2连接在一起

i want to be able to update the agedcare using the id from user_login as the main id 我希望能够使用user_login中的id作为主要ID来更新agingcare

$query = "SELECT id FROM agedcare INNER JOIN user_id ON login_users = login_users.user_id WHERE login_users.user_id = '$id'"

The format is something more like.. 格式更像是..

SELECT id,name,age 
FROM Table1 
INNER JOIN Table2 
    ON Table1.Field=Table2.Field

Another way to simplify the select statement (so that you avoid using the table names throughout) is to "rename" the table right after you name it. 另一种简化select语句的方法(这样可以避免在整个过程中使用表名)是在命名后立即“重命名”表。 For example, the line that has "FROM Table1 T1" - the T1 immediately after the table name is "renaming" the table allowing you to shorten the table name when you need to refer to it. 例如,具有“FROM Table1 T1”的行 - 表名后面的T1是“重命名”表,允许您在需要引用时缩短表名。 In addition, you can use the t1 and t2 identifiers when selecting the fields. 此外,您可以在选择字段时使用t1和t2标识符。

SELECT t1.id,t1.name,t2.age FROM Table1 T1 INNER JOIN Table2 T2 ON T1.Field=T2.Field SELECT t1.id,t1.name,t2.age FROM Table1 T1 INNER JOIN Table2 T2 ON T1.Field = T2.Field

检查你的加入格式,它必须是这样的

SELECT * FROM t1 as a LEFT JOIN t2 as b ON a.id=b.id where user_id = 'id'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM