简体   繁体   English

过滤具有多个表的产品列表

[英]Filtering a product list with multiple tables

First of all, I am quite "new" to php/mysql.首先,我对 php/mysql 很“新”。 I know some basic stuff and am following a course at Udemy right now.我知道一些基本的东西,现在正在 Udemy 学习课程。 (Tips always welcome) (提示总是受欢迎的)

I have the following issue:我有以下问题:

  • I would like to generate an Article list from multiple Tables:我想从多个表中生成一个文章列表:

The List should contain our Article Number and the EAN and should only include Articles that are not already Listed in the SupplierData Table (So it will only contain Articles with missing Supplier info)该列表应包含我们的文章编号和 EAN,并且应仅包含尚未在供应商数据表中列出的文章(因此它将仅包含缺少供应商信息的文章)

Table 1 ( ArticleDB)表 1(文章数据库)

Artnr艺人 Ean伊恩 Price价格
1000 1000 row 1,99 1,99
1001 1001 row 2,99 2,99
1002 1002 row 2,99 2,99
2000 2000 row 2,99 2,99
3000 3000 row 2,99 2,99

Table 2 (SupplierData)表 2(供应商数据)

Artnr艺人 SupplierID供应商 ID SupplierArtnr供应商Artnr
1000 1000 70 70 row
1000 1000 60 60 row
1002 1002 60 60 row
1002 1002 70 70 row
1001 1001 81 81 row

What I tried for now:我现在尝试的:

SELECT a.artnr, a.ean
FROM ArticleDB AS a
JOIN SupplierData AS b ON a.artnr = b.artnr
WHERE a.artnr NOT IN
(
SELECT Artnr
FROM SupplierData
WHERE SupplierID = 70
);

But it keept giving me a list with Data from other Suppliers.但它一直给我一个包含其他供应商数据的列表。 While i would like it ti only give out Numbers + EAN that are in ArtibleDB and do not yet have an entry in SupplierData for SupplierID 70虽然我希望它只给出 ArtibleDB 中的数字 + EAN,但在供应商数据中还没有供应商 ID 70 的条目

Example I was trying to get:我试图得到的例子:

Artnr艺人 Ean伊恩
1001 1001 row
2000 2000 row
3000 3000 row

Am I missing something?我错过了什么吗? Or does someone have an other idea how to make this work?或者有人有其他想法如何使这项工作?

Kind regards,亲切的问候,
Stan斯坦

I have got my answer (While testing and trying):我得到了答案(在测试和尝试时):

SELECT  a.artnr, a.ean
FROM    ArticleDB AS a
LEFT OUTER JOIN    SupplierDATA AS b ON a.artnr = b.artnr
WHERE   a.group != '---'
AND    a.group != 'TEC' 
AND    a.group != 'SER' 
AND a.artnr NOT IN
        (
            SELECT  Artnr
            FROM    SupplierData
            WHERE   SupplierID = 70
        )
      GROUP BY artnr
      ORDER BY artnr ASC;

Seems I had to force it to Group by artnr似乎我不得不强迫它通过 artnr 分组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM