Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
1.67/5 (2 votes)
See more:
UserINfo Table

what is the select query to show like the below table
SQL
+-----+--------+-------+
|   1 | female | Lisa  |
|   2 | male   | Greg  |
|   3 | female | Mary  |
|   4 | male   | John  |
|   5 | female | Jenny |
+-----+--------+-------


Sql Query:: select Id,Name,Sex from UserINfo order by ROW_NUMBER() over (PARTITION BY Sex order by Id),Sex asc

I want use distinct for Name..What would be the query? 
and if i use inner join what would be the query
Posted
Updated 28-Oct-14 21:13pm
v4
Comments
Sanchayeeta 28-Oct-14 8:54am    
Show your table structure.
King Fisher 28-Oct-14 8:57am    
show your table with Sample Data's .
Kornfeld Eliyahu Peter 28-Oct-14 8:58am    
http://mattgemmell.com/what-have-you-tried/

Try to add your table id here,
SQL
select Id,Name,Sex from UserINfo order by ROW_NUMBER() over (PARTITION BY Sex order by Id),Sex asc

(Or) try Group by
SQL
select Id,Name,Sex from UserINfo group by Name,Id,Sex order by ROW_NUMBER() over (PARTITION BY Sex order by Id),Sex asc
 
Share this answer
 
v2
Comments
vangapally Naveen Kumar 28-Oct-14 9:28am    
nice answer....
Rajesh waran 28-Oct-14 9:30am    
Thank You.
King Fisher 29-Oct-14 0:21am    
Good Job Gopu Raj my 5+
Rajesh waran 29-Oct-14 0:27am    
Thank you @King_Fisher
aiswarjya 29-Oct-14 2:48am    
in this query i want to use "DISTINCT".Please Help me
Try this : with Distinct function

SQL
select  distinct id,Name,Sex , ROW_NUMBER() over (PARTITION BY Sex order by id)as rows from UserINfo  order by rows,sex asc
 
Share this answer
 
Comments
tewodrosabebe 21-Apr-18 13:44pm    
write the program vb.net which displays you first name last name,your sex and your id declare first and last name global s
of string type

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