SQL select NOT IN

Open to all! Ask other shopowners for help.
Post Reply
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

SQL select NOT IN

Post by Pierre_P »

Hello

Need some help on this.
I'm trying to exclude certain categories when creating and exporting products to a csv file
For my life i am not getting this part to exclude the categories or am i going the wrong way?

Code: Select all

            $filelayout_sql = "SELECT
            p.products_id as v_products_id,
            p.products_model as v_products_model,
            p.products_status as v_status,
            p.products_price as v_products_price,
            p.products_quantity as v_products_quantity,
            p.products_weight as v_products_weight,
            p.products_image as v_products_image,
            $ep_additional_layout_product_select
            p.manufacturers_id as v_manufacturers_id,
            p.products_date_available as v_date_avail,
            p.products_date_added as v_date_added,
            p.products_tax_class_id as v_tax_class_id,
            p.products_gtin as v_products_gtin,
            
            subc.categories_id as v_categories_id,
	    p.vendors_id as v_supplier
            FROM
            products as p,
            
            categories WHERE NOT IN (SELECT categories_id FROM categories WHERE categories_id = (64,103,146,157,159,160,163,165,166,167,168,169,170,171,172,173,174,182,205) as subc,
            
            products_to_categories as ptoc
            WHERE
            p.products_id = ptoc.products_id AND
            ptoc.categories_id = subc.categories_id
            " . $sql_filter;
Original code at categories WHERE NOT IN... was categories as subc,


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
burt
Core Team
Posts: 4561
Joined: Tue Oct 29, 2019 9:37 am
Phoenix Version: v1.1.0.8
Has thanked: 252 times
Been thanked: 422 times

Re: SQL select NOT IN

Post by burt »

Pierre_P wrote: Tue May 23, 2023 7:46 am

Code: Select all

categories WHERE NOT IN (SELECT categories_id 
WHERE categories_id NOT IN
I am not here to build for you.
I am here to build with you. Let's help each other.
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: SQL select NOT IN

Post by Pierre_P »

Hi @burt

nope, still fetches all categories
User avatar
Pierre_P
Contributor
Posts: 144
Joined: Fri Mar 12, 2021 5:06 am
Phoenix Version: v1.1.0.6
Has thanked: 21 times
Been thanked: 11 times

Re: SQL select NOT IN

Post by Pierre_P »

Okey, got it now :D

Code: Select all

            WHERE
            subc.categories_id  NOT IN (64,103, 108, 146,157,159,160,163,165,166,167,168,169,170,171,172,173,174,182,205) AND
             p.products_id = ptoc.products_id AND


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply