Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in sql server we have a table in which many of column such as Fname Lname U_id and Uname.Uname is primary key..i get the velue of Fname Lname. there are many data is repeated but i get not repeated data. where Uname=? what i do in place of ?....
Posted
Updated 13-Sep-12 20:10pm
v2
Comments
__TR__ 14-Sep-12 2:08am    
Your question is not clear. Use Improve question link to update your question to provide more details on what is it you are trying to do.

If you are talking about the basic query then have a look at this:
SQL
SELECT * FROM tbUserDetails WHERE UserNAME = ?

Here ? means which user information you want to fetch from database. You'll have to be clear on that. You can use like:
SQL
SELECT * FROM tbUserDetails WHERE UserNAME = 'amit'

Here * means all the columns from the table. If you want only specific columns from table then you can replace the * to your column names separated with comma. Try like this:
SQL
SELECT FName, LName, Address, EmailID, PhoneNo FROM tbUserDetails WHERE UserNAME = 'amit'


Hope it helps.
--Amit
 
Share this answer
 
Comments
Rashid Choudhary 14-Sep-12 2:16am    
i want all information of fname and lname
Rashid Choudhary 14-Sep-12 2:17am    
but data is not repeated
_Amy 14-Sep-12 2:21am    
UserName is Primery Key always. So duplicate records won't come.
Try this:
SELECT FName, LName, UserNAME FROM tbUserDetails WHERE UserNAME = 'amit'
If you are looking for distinct FName & LName from the table you can try this:
SELECT DISTINCT FName FROM tbUserDetails WHERE UserNAME = 'amit'
__TR__ 14-Sep-12 2:18am    
I am not sure if this is what the OP was looking for, but I will give a 5 for explanation :)
_Amy 14-Sep-12 2:20am    
Thanks Tejas. :)
I thought the basics will help him to understand the functionality. So that he can try to get the output by himself. :)
Hi,

I understand you are very new with the technology but you should not use UserName as the primary key, Insted i suggest you to use UserID as the primary key. It will also help more for indexing purpose.

If you are running web application then i suggest you to use UserId as GUID instead of simple numeric value. You can set Unique key to userName if you want unique username.

Hope you got the reason for changing primary key from username to userid.
 
Share this answer
 
Hi,

As i understood, FName, LName columns have repeated values whereas UName is Primary key. See, while saving itself you could have causious that, you would not allow repeated FName and LName values. So, just by applying condition to UName is not sufficient to get distinct values. So, while inserting the data check for the existence of same FName and LName values. As of now for distinct values just query for distinct FName and LName.

hope it helps.
 
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