使用一条sql语句查找两个表的某个字段为某个值时

使用一条sql语句查询这两个表的分数相同的人的名字(使用联合查询)   

create table a(
    id int(10),
    score int(3),
    name varchar(20),
)charset utf8;

create table b(
    id int(10),  
    score int(3),
    name varchar(20)
)charset utf8;
(select name from a where score=99 order by id desc limit 0,10)
union all
(select name from b where score=99 order by id desc limit 0,10);

*  要注意的是a表要与b表字段数要相同

猜你喜欢

转载自blog.csdn.net/qq_41320638/article/details/84727986
今日推荐