mysql - SQL Select Query between 3 tables -


i'm having trouble on creating query pull data 3 tables.

i have job_skus table, skus table, , stage table, , i'm trying select job skus whole month regardless of jobno, example show list of job skus month of april.

the tables' structure

job_sku                             example data   jobno                             j4454             j4454   sku (refences product.sku)        93339             9947   quantity                          500               600   stage                             1                 2  products    sku(primary key)                 93339             9947    description                      galvanised nails  steel rods 900mm  stage  jobno                              j4454             j4454  stage                              1                 2  date                               04/04/2015        12/04/2015 

and on.

i have come query

select jm.sku,jm.quantity,p.description  stage s, products p, job_sku jm  s.date between '2015-04-01' , '2015-04-30'  , jm.stage = s.stage , p.sku = jm.sku 

but seems getting duplicate data in query. need use join of sort, or maybe extract stages date period , join result onto job_sku table?

here's 1 suggestion. others in thread have suggested distinct result in same thing, using exists predicate clarifies intention of query (imo):

select jm.sku      , jm.quantity      , p.description   products p join  job_sku jm     on p.sku = jm.sku exists (     select 1     stage s     s.date between '2015-04-01' , '2015-04-30'        , jm.stage = s.stage ); 

as others have mentioned, ansi joins make query bit easier understand. vendors continue support "," join long live, code wont break, ansi join make easier maintain.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -