[英]How to delete one row from a table and multiple rows on another that are related?
[英]select every row in one table and related rows from another
我有兩個表,我從第一個Table A
制成了第二個Table B
,因為第一個表每本書有52列,而我並不需要全部,從另一方面來說,超過100000行是不可用的。
表B
每本書我都有12列。
表格A包含有關書籍的更多信息,例如published city
, cover kind
等。
現在,我需要在第二個表---> Table B
或新Table B
有另一個字段。
這是我的邏輯:
對於表B
每個isbn
,我需要獲取一個名為city
的列。
可能是這樣的:
foreach isbn in table B,
fetch `city`, `weight`, `price` from table A
我試過這個查詢:
select `isbn`, `weight`, `city` from `database1`.`table1` WHERE
(SELECT `isbn` from `database2`.`table2`);
但這似乎不是正確的方法。 您能否幫助我找到使用SQL的正確方法?
提前致謝
您可以簡單地加入兩個表:
SELECT t1.isbn, t1.weight, t1.city
FROM table1 t1
JOIN table2 t2 ON t1.isbn = t2.isbn;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.