![](/img/trans.png)
[英]Taking ids from two rows of one MySQL table and entering those values in one row of another MySQL table using PHP
[英]Selecting two rows from another table using one row
表格1
[ id - title - content - class ]
[ 1 - 2 - 3 - 1 ]
[ 1 - 2 - 3 - 2 ]
表2
[ id - data - permission - class ]
[ a - b - c - 1 ]
[ a - b - c - 2 ]
在選擇所有table1時如何從table2中選擇列data
我的查詢是SELECT title, content FROM table1 WHERE class = 1
如何在此查詢中選擇列data
和permission
?
假設關系基於類:
select table1.*,table2.data, table2.permission
from table1
join table2 on table1.class = table2.class
where table1.class = 1
您可以使用簡單的JOIN
來做到這一點:
Select T1.*, T2.Data, T2.Permission
From Table1 T1
Join Table2 T2 On T1.Class = T2.Class
Where T1.Class = 1
select t1.title, t1.content, t2.data from table1 t1 join table2 t2
on t1.class=t2.class
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.