Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

UserID GrpID Rights

 

U001 A V

U001 B M

U002 A V

U003 A V

U003 B M

 

There are two groups A and B. I want to select all the user_id's but if there are any duplicates, i want to select the user_id which has Rights "M"

 

In simple words, can anyone please tell me a select statement that displays,

 

UserID Rights

U0001 M

U0002 V

U0003 M

 

Please do help me out.

  • Leaders
Posted

Maybe not the most efficient way, but it should get you going for now...

SELECT Distinct(T1.UserID),  (SELECT Min(T2.Rights)  From Table1 T2 WHERE T2.UserID = T1.UserID) As Rights From Table1 T1 

--tim
Posted
quwiltw, thanks for replying. Instead of using select statement, can we use store it in a dataset and then delete duplicate rows where Rights="V". Is it possible.
Posted

hi vidya,

Try this query ( as per the sample data you given),let me know..

 

SELECT USERID, RIGHTS

FROM [uSER]

WHERE RIGHTS = 'M' OR USERID NOT IN (SELECT USERID FROM USER WHERE RIGHTS <> 'M') AND

RIGHTS = 'V' OR USERID NOT IN (SELECT USERID FROM USER WHERE RIGHTS <> 'V');

 

 

Raju

Posted

quwiltw,

 

Can please clarify whether "max" means it displays last row added and "min" means it displays the very first row added as i am not using the primary key here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...