简体   繁体   中英

Filtering a product list with multiple tables

First of all, I am quite "new" to php/mysql. I know some basic stuff and am following a course at Udemy right now. (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)

Table 1 ( ArticleDB)

Artnr Ean Price
1000 row 1,99
1001 row 2,99
1002 row 2,99
2000 row 2,99
3000 row 2,99

Table 2 (SupplierData)

Artnr SupplierID SupplierArtnr
1000 70 row
1000 60 row
1002 60 row
1002 70 row
1001 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

Example I was trying to get:

Artnr Ean
1001 row
2000 row
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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