Mysql 从所有表中具有相同主键的多个表中获取数据

Mysql 从所有表中具有相同主键的多个表中获取数据,mysql,sql,select,join,Mysql,Sql,Select,Join,我有4个表,它们都具有相同的主键,结构如下: table_1 : u_id | col1 | col2 table_2 : u_id | col3 | col4 table_3 : u_id | col5 | col6 table_4 : u_id | col7 | col8 我想根据u\u id的值获取“col1”、“col4”、“col6”和“col7”的数据 u\u id的值在每个表中都是相同的 例如,如果u\u id='8',则在u\u id='8'中

我有4个表,它们都具有相同的主键,结构如下:

table_1 : u_id | col1 | col2    

table_2 : u_id | col3 | col4     

table_3 : u_id | col5 | col6    

table_4 : u_id | col7 |  col8
我想根据
u\u id
的值获取
“col1”、“col4”、“col6”和“col7”的数据

u\u id
的值在每个表中都是相同的

例如,如果
u\u id='8'
,则在
u\u id='8'
中获取所有指定的列值

我想我没有正确使用连接


谢谢。

这应该很简单。使用
内部联接

SELECT  a.col1, b.col4, c.col6, d.col7
FROM    table1 a
        INNER JOIN table2 b
            ON a.u_id = b.uid
        INNER JOIN table3 c
            ON a.u_id = c.uid
        INNER JOIN table4 d
            ON a.u_id = d.uid
WHERE   a.u_ID = 8
要了解有关联接的更多信息,请参阅下面的文章

SELECT 
table_1.col1, 
table_2.col4, 
table_3.col6, 
table_4.col7 
FROM
table_1,
table_2,
table_3,
table_4
WHERE
table_1.u_id = '8' AND
table_1.u_id = table_2.u_id AND
table_1.u_id = table_3.u_id AND
table_1.u_id = table_4.u_id