Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..

can anybody tell me how to get the distinct name from table when same name is added

onto multiple ids where ids are autoincrement
Posted

Just in case you're actually trying to prevent the user from adding the same name twice have a look at UNIQUE[^] constraint.
 
Share this answer
 
SELECT DISTINCT Name FROM TableName
 
Share this answer
 
Is this for adding a record? Try this code. I made it easy for you

SQL
IF((SELECT COUNT(*) FROM Users WHERE username = @username) > 0)
BEGIN
   -- USER ALREADY EXISTS
END
ELSE
BEGIN
   INSERT INTO Users(username, password)
   VALUES (username, password)
END


Regards,
Eduard
 
Share this answer
 
try this

SQL
SELECT DISTINCT name
FROM TableName


use DISTINCT keyword

thanks hope it helps
 
Share this answer
 
v2
Comments
[no name] 6-Dec-11 3:10am    
EDIT: added code block
this is solution

SQL
with CTE(Name,Action_ID,dupname) as
            (select Name,Action_ID,ROW_NUMBER() over(partition by Name order by Name) as dupname  from ActionTypeMaster )
            select * from CTE where dupname=1   order by Name
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900