티스토리 뷰
[ 개별 테이블 LIMIT 적용 ]
$query = "";
$query .= "( SELECT 'A1' as tName, b_code, subject, reg_date FROM t_board_008 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
$query .= " union ";
$query .= "( SELECT 'A2' as tName, b_code, subject, reg_date FROM t_board_009 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
$query .= " union ";
$query .= "( SELECT 'A3' as tName, b_code, subject, reg_date FROM t_board_014 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
$query .= " union ";
$query .= "( SELECT 'A4' as tName, b_code, subject, reg_date FROM t_board_037 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
$query .= " union ";
$query .= "( SELECT 'A5' as tName, b_code, subject, reg_date FROM t_board_038 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
$query .= " union ";
$query .= "( SELECT 'A6' as tName, b_code, subject, reg_date FROM t_board_066 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
$query .= " union ";
$query .= "( SELECT 'A7' as tName, b_code, subject, reg_date FROM t_board_010 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ) ";
:: 각 라인을 () 묶고 개별 LIMIT 적용
------------------------------------------------------------------------------------------
[ 합치기 적용 후 LIMIT 적용 ]
$query = "";
$query .= "SELECT 'A1' as tName, b_code, subject, reg_date FROM t_board_008 WHERE state='1' AND viewYN = 'Y' ";
$query .= " union ";
$query .= "SELECT 'A2' as tName, b_code, subject, reg_date FROM t_board_009 WHERE state='1' AND viewYN = 'Y' ";
$query .= " union ";
$query .= "SELECT 'A3' as tName, b_code, subject, reg_date FROM t_board_014 WHERE state='1' AND viewYN = 'Y' ";
$query .= " union ";
$query .= "SELECT 'A4' as tName, b_code, subject, reg_date FROM t_board_037 WHERE state='1' AND viewYN = 'Y' ";
$query .= " union ";
$query .= "SELECT 'A5' as tName, b_code, subject, reg_date FROM t_board_038 WHERE state='1' AND viewYN = 'Y' ";
$query .= " union ";
$query .= "SELECT 'A6' as tName, b_code, subject, reg_date FROM t_board_066 WHERE state='1' AND viewYN = 'Y' ";
$query .= " union ";
$query .= "SELECT 'A7' as tName, b_code, subject, reg_date FROM t_board_010 WHERE state='1' AND viewYN = 'Y' ORDER BY reg_date DESC LIMIT 1 ";
:: 마지막 라인에만 LIMIT 적용
'Language > MySQL' 카테고리의 다른 글
[ MySQL ] 두개의 필드값 중 높은값 으로 정렬 / 낮은 값 (0) | 2021.07.02 |
---|---|
[ MySQL ] 필드값 치환 :: REPLACE (0) | 2021.02.02 |
[ MySQL ] MySQL 에서 Query 로 테이블에 필드 추가하기 :: 필드 위치 이동 :: 순서 바꾸기 (0) | 2018.12.27 |
[ MySQL ] JOIN - INNER JOIN / OUTER JOIN (0) | 2017.04.06 |
[ MySql ] JOIN 속도를 빠르게! EXPLAIN, STRAIGHT_JOIN (0) | 2017.04.06 |