从每个表中按主键(EID,CID,FID,EnID)降序选择所有记录

时间:2019-06-17 23:19:35

标签: sql oracle

需要一个SQL语句,该语句从每个表中按主键ORDER BY降序选择所有记录。

这没有给出完整的说明

SELECT table_name, num_rows counter FROM user_tables;

我已经尝试过:

SELECT table_name, num_rows counter FROM user_tables;

我希望以主键降序列出所有4个表的输出ORDER BY EID,CID,FID和ENID

1 个答案:

答案 0 :(得分:0)

您可以为此使用联合...

SELECT EID AS ID, 'Engineers' AS TableName FROM Engineers
UNION
SELECT SID, 'Staff' FROM Staff
UNION
SELECT FID, 'Classes' FROM Classes
UNION
SELECT ENID, 'StudentEnrollments' FROM StudentEnrollments
ORDER BY 1

在这种情况下,“ ORDER BY 1”表示第一列。