sql - How to get single row using Group By and Having on column containing varchar value -


i have table containing n columns, taking sample like

dept_id user_id data -------------------- 1             j 1       s       j 1       j       j 2       j       j 2       k       j 2       k       l 3       j       l 3       j       l 

now, in case there more 1 data set dept_id contain differently set flags user_id, data set user_id = ‘j’ selected.

i have tried using

select dept_id, user_id  deleteme  group dept_id, user_id having user_id = 'j'  order dept_id 

however giving me results .

dept_id user_id --------------- 1       j 2       j 3       j 

but requirement is,

dept_id user_id data -------------------- 1       j       j 2       j       j 3       j       l 

please suggest.

select distinct dept_id,user_id, data   @deleteme  user_id='j'  order dept_id    dept_id user_id data -------------------- 1       j       j 2       j       j 3       j       l 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -