mysql - MS-ACCESS How to create query to select all records with fields matching from another query? -


i know question may sound confusing, let me try simplify it.

i have query, let's call query1, , larger table of products. here query1:

item_code    description    order_qty    option 1000         prod1          5            blue 1005         prod5          3            brown 1602         prod6          1            red 5620         prod8          6            yellow 9865         prod2          1            brown 1624         prod3          3            brown 9876         prod12         4            blue 

now in table, have bigger list of products same format. want make new query contains blue, brown, red, , yellow. works, there duplicate.

i'm not sure how post attempt i'll explain tried. made new query , included table , query1. made relationship between two, include rows "option" equal. reason resulting query come out repeats. such as:

item_code    description    order_qty    option 1000         prod1          5            blue 1009  <--    prod2          6            blue     1009  <--    prod2          6            blue     1010  <--    prod9          7            blue     1010  <--    prod9          7            blue     1011  <--    prod11         9            blue     1011  <--    prod11         9            blue     9876  <--    prod12         4            blue     9876  <--    prod12         4            blue 1005  <--    prod5          3            brown 1005  <--    prod5          3            brown 9865  <--    prod2          1            brown 9865  <--    prod2          1            brown 1624  <--    prod3          3            brown 1624  <--    prod3          3            brown 9877         prod99         7            brown 1111  <--    prod67         8            brown    1111  <--    prod67         8            brown     1602         prod6          1            red 1752         prod56         2            red 5620         prod8          6            yellow 

and worst part is, won't repeat. maybe i'm approaching wrong.

i know may case of tldr, if great.

thanks.

sounds need add group by clause or distinct keyword query.

select distinct item_code, description, order_qty, option 

(or click on whatever option in access same thing.)

it's impossible diagnose why query returning "duplicate" rows given information you've provided.

the query returning "duplicate" rows when row in all_products matching 2 or more rows query1, copy of row all_products each matching row query1.


you might better performance if got distinct list of option query1. (i don't "do" ms access. brought question because tagged "mysql". jet database engine cool , all, doesn't work in multiuser environment.) in sql server, oracle, mysql, db2, teradata, et al. we'd write query this:

select p.item_code      , p.description      , p.order_qty      , p.option   mytable p   join ( select q1.option            query1 q1           group q1.option        ) q     on q.option = p.option 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -