써먹는 웹개발
[MariaDB] 'selects cannot be used in field list?' 해결방법 본문
728x90
반응형
1. 변경전
1
2
3
4
5
6
7
8
9
10
11
12
|
select b.app_user_id,b.username,a.message_content,a.message_to,a.message_date
from app_messages a
left join app_users b
on a.message_from = b.app_user_id
where a.message_to=1 and b.app_user_id= 4
UNION
select b1.app_user_id,b1.username,a1.message_content,a1.message_to,a1.message_date
from app_messages a1
left join app_users b1
on a1.message_from = b1.app_user_id
where a1.message_to=4 and b.app_user_id= 1
order by a1.message_date,a.message_date
|
cs |
2. 변경후 : select로 묶어서 해결
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
select * from
(
select b.app_user_id,b.username,a.message_content,a.message_to,a.message_date
from app_messages a
left join app_users b
on a.message_from = b.app_user_id
where a.message_to=1 and b.app_user_id= 4
UNION
select b1.app_user_id,b1.username,a1.message_content,a1.message_to,a1.message_date
from app_messages a1
left join app_users b1
on a1.message_from = b1.app_user_id
where a1.message_to=4 and b1.app_user_id= 1
)A order by message_date
|
cs |
728x90
반응형
'웹개발 > Database' 카테고리의 다른 글
[MYSQL] 에러 번호 1175 Safe Update 해결방법 (0) | 2023.09.12 |
---|---|
[Mariadb] 테이블에 중복 데이터 있는지 확인하는 쿼리문 (0) | 2023.09.06 |
[MySQL || MariaDB] 데이터베이스 접근 권한 거부 Host 'IP' is not allowed to connect to this MySQL server (0) | 2023.08.11 |
[MariaDB] 테이블 및 데이터 백업 명령어 (+function(routines)) (0) | 2023.08.11 |
[mariadb] function case 예시 (0) | 2023.07.13 |
Comments