Наличие двух операторов выбора в одном - PullRequest
0 голосов
/ 28 февраля 2019

Я смотрел в других темах так же, как мои, но они, похоже, не отвечали на мой вопрос.

У меня есть этот код здесь:

select * from outerbarcodes where not exists (select 1
              from bridgebarcodes
              where bridgebarcodes.barcode = outerbarcodes.barcode
             )
             union SELECT productcode, Brand, product, size, barcode FROM outerbarcodes WHERE
COALESCE(productcode, '') <> '' AND
COALESCE(Brand, '') <> '' AND
COALESCE(product, '') <> '' AND
COALESCE(size, '') <> ''

Я не понимаюпочему UNION не работает?

Это моя колонка настроена:

Таблица: bridgebarcodes Столбцы: ID int (11) AI PK ProductCode varchar (100) Штрих-код varchar (100)

Таблица: внешние штрих-коды Столбцы: id int (11) AI PK ProductCode varchar (100) Марка varchar (100) Продукт varchar (100) размер varchar (100)) Штрих-код varchar (100)

1 Ответ

0 голосов
/ 28 февраля 2019

2 запроса UNION должны иметь одинаковое количество столбцов, а столбцы должны иметь одинаковый тип данных, поэтому измените его на:

select productcode, Brand, product, size, barcode from outerbarcodes where not exists (select 1
              from bridgebarcodes
              where bridgebarcodes.barcode = outerbarcodes.barcode
             )
             union SELECT productcode, Brand, product, size, barcode FROM outerbarcodes WHERE
COALESCE(productcode, '') <> '' AND
COALESCE(Brand, '') <> '' AND
COALESCE(product, '') <> '' AND
COALESCE(size, '') <> ''
...