mysql同时查两张表,怎么优先返回第一张表数据?

** mysql同时查两张表,怎么优先返回第一张表数据?**(描述:有3个系统,优先取系统3,系统3不存在对应数据则取系统2,系统2不存在数据取系统1)
[表字段一样,就是查了两次同一张表的不同类型]

create table tbl_org_info
(
    ID                  bigint auto_increment comment 'ID.'
    ORG_CODE            varchar(50)    default ''                not null comment '机构编码',
    ORG_NAME            varchar(50)    default ''                not null comment '机构名称',
    SOURCE_TYPE         smallint(4)    default 1                 not null comment '数据来源,1:系统一,2:系统2,3:系统3'

)

主要还要看具体的业务需求,如果两张表的数据是不同业务表,有关键key做join的话,可以用left join,将第一张表放在前面,就会优先取第一张表的数据。如果是相同业务表,在两张表设置一下排序号(可手动构建),select * from (select col,1 as num from table1 union select col,2 as num) order by num limit 20; 这种形式,通过人为干预排序号来让数据有限被查询到。

select * from tbl_org_info a where a.SOURCE_TYPE=(select distinct b.SOURCE_TYPE from tbl_org_info b ORDER BY b.SOURCE_TYPE desc limit 1)