简体   繁体   中英

joining table with itself using mysql

When I write this line on mysql on phpmyadmin using mariadb server getting unexpected error near a.cpid = b.cid

select a.cid, a.cname as 'cname', b.cname as 'pname'
from categories as a left OUTER JOIN as b ON a.cpid = b.cid

MySQL said:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'as b ON a.cpid = b.cid LIMIT 0, 25' at line 1

You lack a table name (the second categories in below):

select a.cid, a.cname as 'cname', b.cname as 'pname' 
from categories as a 
left OUTER JOIN categories as b ON a.cpid = b.cid

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