SQL Server :: How To Bring Distinct Result
Jan 5, 2011I need to bring the distinct result in third columnBelow one is my sample table
[Code]....
I need to bring the distinct result in third columnBelow one is my sample table
[Code]....
(ie.)C-Chennai
B-Bombay
-Hydrabad
A-Andhra
K-Karnataka
It may comes any order but (cbhak) is constant. i need to bring this in query, i dont want to use any funtionHow can i acheive this result
Tag TableName FieldNameabc wc s_namelbl wc s_deslb2 wc s_prodin above fieldname(s_name,s_des,s_prod) column represent field in wc table.How can i bring this result. is this possible without using cursor. i was struggling past two days. i cant able to bring result for above.
View 17 RepliesI have the following table structure:
[code]....
The following query returns the default recordset:
[code]....
i need record with id 1 and 3 only how do i get in sql server 2005.(means distinct empcod onl.
View 3 RepliesI have one table(tableName is getDetails and having three column ID, Name, City)
View 6 RepliesCan any one please guide, how to bring this output.Below one is Sample Data
[Code]....
I'm a little frustrated here. I have turned the default database offline then used windows explorer to copy the database to another location but when I tried to take the database online again this error came out:
Cannot open user default database. Login failed. Login failed for user 'Zephere-pcephere(JuLian Yong)'. (Microsoft SQL Server, Error: 4064) The cause is that the default database is set offline, How do I bring it back online agian?
I would like to select a distinct query based on three fields and display the rest of the fields. For example,
I have firstname, lastname, address, city, state and zip, but I only want to use the distinct on these fields first and last name. However when i use the distinct function I get a distinct on all the selected rows. I just want to distinct firstname and lastname and display the other fields. for example,
Mary Smith New York
Mary Smithy New York
Mary Smith Maine
I would like the result to be:
Mary Smith New York
Mary Smithy New York
I don't care about Mary Smith Maine, because i am only using the distinct for "Mary Smith" firstname and last name and showing the city.
I have tableone:
rowid pid gid dis
1 1222 aa dd
2 1222 bb cc
3 1222 cc dd
4 1331 vv cc
5 1331 cc zz
6 1414 zz cc
5 1414 xx zz
I need get distinct pid with rowid together. select * distince pid from tableone However, I get error: select rowid, distinct pid from tableone? Is any way to work out this one?
Here's my current table data.
AccountNumber Product
00505871 Product1
00505871 Product2
00503297 Product3
00900004 Product4
00505871 Product3
00514884 Product3
00503297 Product2
00505871 Product1
How can I achieve following result.
AccountNumber ProductString
00505871 Product1,Product2,Product3,
00503297 Product2,Product3
00900004 Product4
00514884 Product3
how can i use Distinct in my sql statement like that
SELECT
Distinct * from my_table ?? ? ? ?? ? ? ?
I have a one sql table, it contain 5 column id, ipaddress, status, datetime, value. I need to find distinct rows as per ipaddress column basic..
View 7 RepliesI have a table 'tbl' and a column 'col'. The elements are like 1,1,2,2,2,3,4,4. Now I want to show two columns one is the one will contain the distinct values from 'col' like 1,2,3,4.... and second will contain the count for each of them like for above case it will be 2,3,1,2.
View 1 RepliesI have the data below:
id locationid cookieid username IPAddress createdate
1 704 192.168.0.103 2010-12-08 18:11:24.423
2 704 192.168.0.103 2010-12-08 18:13:26.133
3 704 myname@hotmail.com 192.168.0.103 2010-12-08 18:13:47.710
4 704 myname@hotmail.com 192.168.0.103 2010-12-08 18:16:42.730
5 704 myname@hotmail.com 192.168.0.103 2010-12-08 18:17:00.433
6 704 myname@hotmail.com 192.168.0.103 2010-12-08 18:18:09.867
7 1504 myname@hotmail.com 192.168.0.103 2010-12-08 18:26:01.447
Now, I want to select all unique locationid's from a single username, its important that the results can be PAGED and SORTED, I now have:
SELECT * FROM (select ROW_NUMBER() OVER (ORDER BY createdate) as RowNum,
distinct(locationid), l.*
FROM location_views lv
INNER JOIN locations l on l.id=lv.locationid
where lv.username='myname@hotmail.com'
) as info
WHERE RowNum > 0 AND RowNum <= 100
But this throws the error: "Incorrect syntax near the keyword 'distinct'."
This is my last thread [URL] ....
This sp show duplicate row yet, what can i do?
I would like to know if there is a way that I can use DISTINCT on one column's values but need to show other columns where the value of the DISTINCT column is equal to another table's column
View 7 RepliesHow can i select all columns of table but to distinct by one column? i am tryin to figure it out without success, i know how to make distinct (select distinct column from table, but i need all the values from the table and to distinct by Delcompany.
my line is:
[Code]....
I have a table with 2 columns that lookes something like this:
ChapterID | VersionNumber | VersionID |
1001 | 1 | 1004 |
1001 | 2 | 1005 |
1002 | 1 | 1006 |
1002 | 2 | 1007 |
1002 | 3 | 1008 |
1003 | 1 | 1009 |
1004 | 1 | 1010 |
what I wanna achieve is to have a statement that selects distinct uniqueid's from the chapterID field and with every duplicate I would like to have the record with the highest version number
Below is the result I would like to achieve:
ChapterID | VersionNumber | VersionID |
1001 | 2 | 1005 |
1002 | 3 | 1008 |
1003 | 1 | 1009 |
1004 | 1 | 1010 |
I have tried this statement:
Select Distinct ChapterID, max(VersionNumber) from Versions groupby ChapterID
and it works fine, but when I add the VersionID column like so:
Select Distinct ChapterID, VersionID, max(VersionNumber) from Versions group by ChapterID
it returns an error.
Background: I use stored procedures exclusively for an ASP.NET application. I am using a DataReader to load a dataset object.
View 4 RepliesI have a page where I'm displaying all the different brand that I company stocks
For each distinct brand I need to display a count of the number of items with that particular brand
e.g.
brand name
number of products with that brand
brand name 2
number of products with that brand
brand name 3
number of products with that brand
I have this ListView that has a Drop Down List.Everything works fine (I think/hope) except that the drop down list are not showing its result correctly.This is the code.
Front-End
[Code]....
The code behind consist of the page_load and the ItemDataBound
[Code]....
I'm having a problem with my Linq to XML query. I'm getting the result data I want, but it's nested so deep that there must be a better way.Here is my XML:
[Code]....
I'm trying to get a list (simple string[]) of all Item IDs where Category Names contains "Other".Here is my Linq:
[Code]....
[Code]....
Here is a snapshot of my result from Visual Studio:The results I want are there ("item100", "item400", "item500"), but buried so deeply in the results var.
How can I get the query to return a simple
string[] = { "item100", "item400", "item500" }
I am looking for an example where I create CTE, and then using the result of first CTE, I create another CTE.With CTE1 as ( Col1, Col2, Col3)
(
--SOME RECURSIVE QUERIES
)
select Col1, Col2, Col3 from CTE1 where Col3 >100I want to now use the above query inside a recursive CTE2. One way is to store the above result in a temp table and use the temp table in a new CTE but I am NOT looking for temp table solution here. May be wrap the above result in another CTE, but I am missing the syntax.
I have the following request:
[Code]....
its result is:
ProductSUM
1355
310
210
220
150
95
60
235
90
545
How to SUM these values?