을 만들 수 있습니다 모든 4 개의 쿼리의 결과 집합과 결합 된 결과 집합에서 뷰를 만듭니다.결합 결과 집합은 각 선택 쿼리 전을위한 조건 지정된 최신 기록 회의를 제공합니다 나는 4 개 개의 다른 테이블 4 Select 문을보기
답변
일부 DB의 경우 통합 쿼리에서 "order by"절을 사용할 수 없습니다.
col1 desc로 주문하는 경우 min() 또는 max()를 적용 할 수있는 몇 가지 유형의 열일 수 있습니다.
이런 경우, 아래 문제를 해결할 수 (테이블이 거대한 경우, "COL1"및 "some_column"색인, 너무 많은 레코드가없는 경우, 또는.)
create view some_view as
(
select * from table1
where some_column = 'something'
and col1 = (select max(col1) from table1 where some_column = 'something')
UNION ALL
select * from table2
where some_column = 'something'
and col1 = (select max(col1) from table2 where some_column = 'something')
UNION ALL
select * from table3
where some_column = 'something'
and col1 = (select max(col1) from table3 where some_column = 'something')
UNION ALL
select * from table4
where some_column = 'something'
and col1 = (select max(col1) from table4 where some_column = 'something')
)
create view some_view as
(
(select TOP 1 * from table1 where ....)
UNION ALL
(select TOP 1 * from table2 where ....)
UNION ALL
(select TOP 1 * from table3 where ....)
UNION ALL
(select TOP 1 * from table4 where ....)
)
UNION 구문으로 주문을 사용할 수 없습니다. – AChamp
@AChamp 제한 조항이있는 한 (즉, 'TOP 1') –
다음은 작동하는 모습을 보여주는 SQL 피들 예제입니다 ... http://sqlfiddle.com/#!3/1f7f3/1 –
어쨌든 당신의 문제는 무엇입니까? 나는 당신이 당신의 문제에 대답했고, 결과를보기를 만들어 결합하는 것 같아요. –
@patrickchoi : 분명히 그는 그들을 결합하는 방법을 알지 못합니다. (예 : UNION 키워드) –