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;
'프로그래밍 > SQL' 카테고리의 다른 글
mysql- Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. (0) | 2019.12.14 |
---|---|
outer join - mysql (0) | 2019.11.28 |
workbench에서 readonly 해제하기 (0) | 2019.11.28 |
mysql - Error Code: 1248 Every derived table must have its own alias (0) | 2019.11.22 |
mysql workbench에서 BLOB 타입 데이터 안나올 때 (0) | 2019.11.12 |
WRITTEN BY