MySQL----一个表查询到的值作为条件查询同一个表的值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/damys/article/details/81109061

表简单结构

CREATE TABLE IF NOT EXISTS table_school(    
    school_id smallint unsigned NOT NULL AUTO_INCREMENT COMMENT '校区id',
    city_pid smallint unsigned NOT NULL COMMENT '父级校区所在市id',
    school_name varchar(32) NOT NULL DEFAULT '' COMMENT '名称',
    school_intro varchar(255) NOT NULL DEFAULT '' COMMENT '简介',
    KEY(city_pid),
    PRIMARY KEY(school_id)
) ENGINE=innoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 COMMENT '校区表';

SQL

select a.*, (select school_name from table_school  where a.city_pid=school_id) as city_name from table_school as a
where a.school_id = :school_id;
展开阅读全文

没有更多推荐了,返回首页