简体   繁体   中英

select every row in one table and related rows from another

I have two tables, that I made second one Table B from first one Table A because first table had 52 columns for every book and I did not need them all and from other hand, more than 100000 rows was unusable.
I have 12 columns for every book in table B .


table A contains some more information about books, like, published city , cover kind , etc...

Now, I need to have another field in second table ---> Table B or in a new one.

This is my logic :
for each isbn in table B , I need to fetch a column named city .

May be like this :

foreach isbn in table B,
         fetch `city`, `weight`, `price` from table A


I tried this query :

select `isbn`, `weight`, `city`  from `database1`.`table1` WHERE 
       (SELECT `isbn` from `database2`.`table2`);

but it seems it's not a right way. Would you please help me to find right way to do this using SQL???

Thanks in Advance

You could simply join the two tables:

SELECT t1.isbn, t1.weight, t1.city 
 FROM table1 t1 
 JOIN table2 t2 ON t1.isbn = t2.isbn;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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