简体   繁体   中英

selecting data from a specific table in a database based on relation with another table

I have two tables: book table with:bid,bname,bownerid,bedition. user table with:uid,uname, upass,uphone. i have created a relation between the two tables between bownerid as a foreign key and uid as its referenced key. my question is how to retrieve the uname from this relation when selecting all from book table.

尝试这个 :

Select U.uname, B.* from user U, book B where U.uid = B.bownerid;

May be this is what you are looking for,

select b.*, u.uname from book b left outer join user u on u.uid = b.bowner_id;

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