ASP.NET - how to select distict value and order by unique value sql

Asked By mani
03-Feb-12 10:15 AM
hi..i have table with column as

sno    modelname
01    nokia
02   Samsung
03   LG
04   Nokia
05    LG
06    Nokia

how to get distinct value of modelname order by sno..
???any help??
  D Company replied to mani
03-Feb-12 10:42 AM
Hello Friend.

use distinct clause , try this query

Select DISTINCT modelname from tablename OEDER BY sno

let me know if it is not working.
Regards
D
  D Company replied to mani
03-Feb-12 10:43 AM
there was a typo in last post please ignore this line.

Select DISTINCT modelname from tablename OEDER BY sno

its

Select DISTINCT modelname from tablename ORDER BY sno
  mani replied to D Company
03-Feb-12 10:44 AM
i used u r query like this but getting error as

Select DISTINCT modelnumber from postquries ORDER BY sno


ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
  D Company replied to mani
03-Feb-12 11:27 AM
use this query,

Select DISTINCT sno,modelnumber from postquries ORDER BY sno

Regards
D
  dipa ahuja replied to mani
03-Feb-12 12:25 PM
Try this way:
 
SELECT DISTINCT modalname
FROM   table1
ORDER BY sno
  Sandeep Mittal replied to mani
04-Feb-12 12:37 AM
When distinct clause is used in "SELECT" stament, it is mandatory to have all the columns used in  "ORDER BY" should exists in "SELECT"

DECLARE @TAB TABLE(
  sno varchar(10), modelname varchar(10)
)
INSERT INTO @TAB   
SELECT '01','nokia'
UNION ALL SELECT '02','Samsung'
UNION ALL SELECT '03','LG'
UNION ALL SELECT '04','Nokia'
UNION ALL SELECT '05','LG'
UNION ALL SELECT '06','Nokia'
 
-- This might give you duplicate values if same modelname is repeated for different sno as in your given data
SELECT DISTINCT sno, modelname
FROM   @TAB
ORDER BY sno
 
-- Use like this
SELECT DISTINCT modelname
FROM (
  SELECT  TOP 100 PERCENT modelname
  FROM    @TAB
  ORDER BY sno
) TAB
Create New Account
help
Net hi friends Any one send frequently asked Important questions in C# .Net, ADO .Net, Asp .Net and Sql Server. . . . . . . . tx in Advance. . . . . . Hi, Find this. . (B)What is an IL? (B A) What is scavenging? (B) What are different types of caching using cache object of ASP.NET? (B) How can you cache different version of same page using ASP.NET cache object? (A) How will implement Page Fragment Caching? (B) Can you compare ASP.NET sessions with classic ASP? (B) Which are the various modes of storing ASP.NET session
security info = False;user id = sa;workstation id = IBM-6BC8A0DACEF;packet size = 4096?; String strCom1 = ”SELECT * FROM employee”; SqlDataAdapter sqlDa1 = new SqlDataAdapter(strCom1, strCon); ds1.Tables.Add(”employee”); sqlDa1.Fill(ds1 Fill(ds, “Products”) DataGrid1.DataSource = ds.Tables(”Products”) What is the maximum length of a varchar in SQL Server? Answer1 VARCHAR[(n)] Null-terminated Unicode character string of length n, with a maximum of 255 characters in Sql server as var_name int How do you separate business logic while creating an ASP.NET application? There are two level of asp.net debugging 1. Page level debugging For this we have to edit the page level debugging can customize the Toolbox: Right-Click the Toolbox> .NET Framework Components> Browse> select the CalenderControl.dll. 4)The Calender Control is now added to the Toolbox and can
All" && DropDownList_state.SelectedItem.Text = = "All" && DropDownList_city.SelectedItem.Text = = "All" && CheckBoxList1.SelectedIndex = = -1) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = true && CheckBoxList1.Items[1].Selected = = false && CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = false && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = false && CheckBoxList1.Items[1].Selected = = false && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = true && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = false ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = true && CheckBoxList1.Items[1].Selected = = false && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = false && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d Selected = = true && CheckBoxList1.Items[1].Selected = = true && CheckBoxList1.Items[2].Selected = = true ) { cmd = new SqlCommand ( "select a.img, a.prop_name, b.state_name, c.city_name, d.price, d.prop_price_type, d.builtup_area, d
Migration from ASP to ASP.net How to convert ASP site to ASP.NET site using C# http: / / www.asp.net / downloads / archived-v11 / migration-assistants / asp-to-aspnet hi, ASP.NET framework is very much different from unstrucured ASP and there is no correct way to
Tracing in ASP.NET? hi all, what is tracing? how to achieve tracing in asp.net? different ways of doing tracing? thanks and regards Aman Khan hi. . Tracing in ASP.NET 2.0 Tracing is a way to monitor the execution of your ASP.NET application. You can record exception details and program flow in a way that doesn't