数据库sql同时读取两个表
表一表二字段完全相同select*from表一whereto_days(datetime)=to_days(now())andusername='$user'orderb...
表一 表二 字段完全相同
select * from 表一 where to_days(datetime) = to_days(now()) and username ='$user' order by id desc
select * from 表二 where to_days(datetime) = to_days(now()) and username ='$user' order by id desc
怎么同时查询两个表?
select * from 表一 表二 where to_days(datetime) = to_days(now()) and username ='$user' order by id desc
我这个显然不行。 展开
select * from 表一 where to_days(datetime) = to_days(now()) and username ='$user' order by id desc
select * from 表二 where to_days(datetime) = to_days(now()) and username ='$user' order by id desc
怎么同时查询两个表?
select * from 表一 表二 where to_days(datetime) = to_days(now()) and username ='$user' order by id desc
我这个显然不行。 展开
3个回答
展开全部
可以这样
select * from 表一 where to_days(datetime) = to_days(now()) and username ='$user'
union all
select * from 表二 where to_days(datetime) = to_days(now()) and username ='$user'
如果你非要排序
select t.*
from
(select * from 表一 where to_days(datetime) = to_days(now()) and username ='$user'
union all
select * from 表二 where to_days(datetime) = to_days(now()) and username ='$user' ) as t
order by t.id desc
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询