before

SELECT 
  a.no,
  a.code,
  b.price,
  b.start_date,
  b.end_date
FROM product a
left join sale b
on a.code = b.code
Union
SELECT 
  a.no,
  a.code,
  b.price,
  b.start_date,
  b.end_date
FROM product a
right join sale b
on a.code = b.code
order by no desc

Error Code : 1221 Incorrect usage of UNION and ORDER BY

 

오류 발생

- union과 order by를 같이 사용할 때에는 select 문을 괄호로 감싸줘야 한다.

 

after

(
SELECT 
  a.no,
  a.code,
  b.price,
  b.start_date,
  b.end_date
FROM product a
left join sale b
on a.code = b.code
)
Union
(
SELECT 
  a.no,
  a.code,
  b.price,
  b.start_date,
  b.end_date
FROM product a
right join sale b
on a.code = b.code
)
order by no desc;​

 


WRITTEN BY
beautifulhill

,