我使用 Union All 进行两个选择查询。查询双方不同,我必须从表和显示中找到记录。我已尝试以下查询,但出现错误
#1064 - 你的 SQL 语法有错误;检查手册 与您的 MySQL 服务器版本相对应,以便使用正确的语法 第 4 行“as table2”附近
SELECT * FROM
(select company_id as ID,concat('https://example.com/axy/',`slug`) as url from company22 c where company_name like '%xyz%' and c.is_active = 1 and admin_approved = 1 order by company_id desc limit 0, 1 ) as table1
UNION All
(SELECT ID, post_title, post_content, post_date FROM `wp_posts` where post_content like '%xyz%' and post_status = 'publish' and post_type='table' order by post_date DESC ) as table2
要使其正常工作,您可以从 UNION 创建子查询,或者根本不使用外部选择
SELECT * FROM
((select company_id as ID,concat('https://example.com/axy/',`slug`) as url from company22 c where company_name like '%xyz%' and c.is_active = 1 and admin_approved = 1 order by company_id desc limit 0, 1 )
UNION All
(SELECT ID, post_title, post_content, post_date FROM `wp_posts`
where post_content like '%xyz%'
and post_status = 'publish'
and post_type='table'
order by post_date
DESC )) tab1;
(select company_id as ID,concat('https://example.com/axy/',`slug`) as url from company22 c where company_name like '%xyz%' and c.is_active = 1 and admin_approved = 1 order by company_id desc limit 0, 1 )
UNION All
(SELECT ID, post_title, post_content, post_date FROM `wp_posts`
where post_content like '%xyz%'
and post_status = 'publish'
and post_type='table'
order by post_date
DESC )