Reputation: 83
I have tables called News
, Sports
, Technology
, Articles
...etc , each table has ID, Title, Content, Image, Date .. The ID
is the primary key in each table, and each table has no relationships, no joins no any thing, they are in the same database but separated.
What I want is to select the last added record from each table (just 1 record from each table) assuming that I ordered them by ID DESC
, to bind them to datalist (Latest/Shuffle).
So what SQL query statement should I use ?
The records in DataList should be like this:
News_ID News_Title News_Content News_Date
Technology_ID Technology_Title Technology_Content Technology_Date
SPorts_ID Sports_Title Sports_Content Sports_Date
and so on....
Any pointers ??
My SQL skills are not so good. Any help is greatly appreciated.
regards.
Upvotes: 0
Views: 948
Reputation: 919
select top 1
News_ID, News_Title, News_Content, News_Date
from News
order by News_ID desc
union all
select top 1
Technology_ID, Technology_Title, Technology_Content, Technology_Date
from Technology
order by Technology_ID desc
union all
select top 1
Sports_ID, Sports_Title, Sports_Content, Sports_Date
from Sports
order by Sports_ID desc
Upvotes: 1