sql - Get Identity after selecting from distinct result -



sql - Get Identity after selecting from distinct result -

i have 2 tables ( model_table , items_table) model_tabl ( id, modelname, modelquantity) items_tabl ( i_code, iname, id)

after inserting new row (model_table) - triggers insert multi row (items_table) depend on modelquantity (model_table) , , until work fine

i created "select distinct modelname , sum(modelquantity) grouping modelname" , got result fine

my question is :

when select model name (distinct) query want know (id) selected (model_table)

model_id (to) model_name = 1 (to) many ty

just do:

select id, modelname , sum(modelquantity) grouping id, modelname

as long id , modelname 1-to-1, you're good.

(btw, "distinct" here superfluous - select distinct a,b,c tbl shorthand select a,b,c tbl grouping a,b,c)

sql sql-server tsql

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -