从两张桌子搜索

时间:2014-02-13 08:43:36

标签: asp.net sql-server

我有两个表我想创建一个搜索查询,我在这两个表中使用正则表达式搜索,这是我想要搜索的查询

SELECT artikel_id as id, artikel_overskrift as overskrift, artikel_keywords as keywords, artikel_text as texten FROM artikler
UNION ALL
SELECT begivenheder_id as id, begivenheder_title as overskrift, begivenheder_keyword as keywords, begivenheder_beskrivelse as texten FROM begivenheder

如何对此查询进行排序和排序

2 个答案:

答案 0 :(得分:0)

是什么阻止您将此查询用作子查询并对其应用order by子句?

如果这不是您想要的,请详细说明您的问题。示例

SELECT * FROM
(
SELECT artikel_id as id, artikel_overskrift as overskrift, artikel_keywords as keywords,     artikel_text as texten FROM artikler
UNION ALL
SELECT begivenheder_id as id, begivenheder_title as overskrift, begivenheder_keyword as keywords, begivenheder_beskrivelse as texten FROM begivenheder
 )TAB1 ORDER BY ID

希望这有帮助。

答案 1 :(得分:0)

我不确定这是否需要进行子选择。

以下内容应该对overskrift列的整个结果集进行排序:

SELECT artikel_id as id, artikel_overskrift as overskrift, artikel_keywords as keywords, artikel_text as texten
FROM artikler
UNION ALL
SELECT begivenheder_id as id, begivenheder_title as overskrift, begivenheder_keyword as keywords, begivenheder_beskrivelse as texten
FROM begivenheder
ORDER BY overskrift