В частности, я хочу выбрать столбец из подзапроса по псевдониму, но это приводит к ошибке.В частности, я ссылаюсь на эту строку из полного запроса ниже:
WHERE id NOT IN (SELECT x.minid (SELECT p.post_title, MIN(m.id) as minid, m.meta_value
...) as x );
create table wp_posts (
ID integer primary key auto_increment,
post_title varchar(30),
post_type varchar(30)
);
✓
create table wp_postmeta (
ID integer primary key auto_increment,
post_id integer,
meta_key varchar(30) not null default '_regular_price',
meta_value integer not null
);
✓
insert into wp_posts (post_title, post_type) values
('Apple Pie','Product'),
('French Toast','Product'),
('Shepards Pie','Product'),
('Jam Pie','Product'),
('Jam Pie','Product'),
('Plate','Not a Product'),
('Bucket','Not a Product'),
('Chequebook','Not a Product'),
('French Toast','Product'),
('French Toast','Product'),
('Banana','Product'),
('Banana','Product'),
('Banana','Product');
✓
insert into wp_postmeta (post_id, meta_value) values
(1,10),
(2,5),
(3,9),
(4,8),
(5,11),
(6,12),
(7,10),
(8,6),
(9,1),
(10,1),
(11,7),
(12,2),
(13,2);
✓
-- Deleting all duplicate products in wp_posts table
DELETE FROM wp_posts
WHERE id NOT IN (SELECT x.minid (SELECT p.post_title, MIN(m.id) as minid, m.meta_value
FROM
wp_postmeta m
INNER JOIN wp_posts p
ON p.id = m.post_id
AND p.post_type = 'Product'
WHERE
m.meta_key = '_regular_price'
AND NOT EXISTS (
SELECT 1
FROM
wp_postmeta m1
INNER JOIN wp_posts p1
ON p1.id = m1.post_id
AND p1.post_type = 'Product'
WHERE
m1.meta_key = '_regular_price'
AND p1.post_title = p.post_title
AND m1.meta_value < m.meta_value
)
GROUP BY p.post_title, m.meta_value) as x
);
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT p.post_title, MIN(m.id) as minid, m.meta_value
FROM
wp_postmeta m
' at line 3
db <> скрипка здесь
Если это невозможно сделать из-за синтаксических правил, как будет Я выберу агрегатный столбец MIN(m.id)
?