mysql - How to join multiple occurrences of record against master record with filter -


i have table shows big library of products.

i have several filters can applied table via kendo grid, problem having concerns mysql.

i have date range filter, needs filter list of products when sold.

the issue having because product have sold more once, causes product lines duplicate, because example 4 "datesold" rows 1 product. know why is, can't figure out how syntax filter:

select ... parts_library left join parts_sale_dates psd on psd.partlibid = parts_library.id 

when applying date filter this:

select ... parts_library left join parts_sale_dates psd on psd.partlibid = parts_library.id psd.datesold >= ? 

another issue doing:

select ... parts_library left join parts_sale_dates psd on psd.partlibid = parts_library.id 

makes query take donkeys because there 500,000 products.

i think looking "between":

select ... parts_library pl left join      parts_sale_dates psd      on psd.partlibid = pl.id psd.datesold between <date1> , <date2>; 

if want just parts no duplicates, can express as:

select distinct pl.* parts_library pl left join      parts_sale_dates psd      on psd.partlibid = pl.id psd.datesold between <date1> , <date2>; 

the performance on large data sets not be, shall say, good.

the following equivalent, should have better performance:

select pl.* parts_library pl exists (select 1               parts_sales_dates psd               psd.partlibid = pl.id ,                     psd.datesold between <date1> , <date2>              ) 

you can improve performance having index on parts_sales_dates(partslibid, datesold).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -