有三个表table1 ,table2 ,table3
结构如下:table1
---------------------------------
tb1ID tb1name tb2Url (字段名)
--------------------------------table2
---------------------------------
tb2ID tb2name tb2Url (字段名)
--------------------------------table3
---------------------------------
tb3ID tb3name tb3Url (字段名)
---------------------------------
ID 都是主键.自动增长
我要取出这三个表每一个最后插入的数据,怎么写??
结构如下:table1
---------------------------------
tb1ID tb1name tb2Url (字段名)
--------------------------------table2
---------------------------------
tb2ID tb2name tb2Url (字段名)
--------------------------------table3
---------------------------------
tb3ID tb3name tb3Url (字段名)
---------------------------------
ID 都是主键.自动增长
我要取出这三个表每一个最后插入的数据,怎么写??
where id = (select max(id) from table1 )
union all
select * from table2 where tb2ID=(select max(tb2ID) from table2)
union all
select * from table3 where tb3ID=(select max(tb3ID) from table3)
select * from (
select top 1 * from table1 order by tab1id desc
) as t1
union all
select * from (
select top 1 * from table2 order by tab2id desc
) as t2
union all
select * from (
select top 1 * from table3 order by tab3id desc
) as t3
SELECT * FROM (SELECT tb1id id,tb1name name,tb1url url,f=1 FROM tb1
UNION ALL
SELECT *,f=2 FROM tb2
UNION ALL
SELECT *,f=3 FROM tb3) x
WHERE 1>(SELECT COUNT(1) FROM
(SELECT tb1id id,tb1name name,tb1url url,f=1 FROM tb1
UNION ALL
SELECT *,f=2 FROM tb2
UNION ALL
SELECT *,f=3 FROM tb3) y WHERE y.f=x.f AND y.id>x.id)没测试