distinct

Mysql: How to select distinct values from a database column

Hi friends, My goal is to select value from "EmbedImgDimension" column where in lots of duplicated values are present. I have used the following query select distinct EmbedImgId, VideoID, EmbedImgHeight, EmbedImgWidth, EmbedImgFileName, concat(embedimgwidth,' x ',embedimgheight) as EmbedImgDimension from embedimages inn...

Alternative to DISTINCT Function

Is there a better way to get all distinct values from three columns in one table other than using the DISTINCT function? I've also tried GROUP BY, but there doesn't seem to be any noticeable difference in the cost. SELECT DISTINCT Table1.Col1, Table2.Col1, Table1.Col3 FROM Table1 INNER JOIN Table2 ON Table1.FK = Table2.ID WHERE Table1....

How to extract a distinct list of records from SQL or Excel

Hi, I have an excel spreadsheet with 15 columns, one of which is EmailAddress and then 100,000+ records.. In my data i know that there are many duplicate email addresses. Can someone tell me how can i extract a distinct list where each record is represented only once by emailaddress? Alternately, if i import the data into SQL, how ca...

Get distinct values of Queryset by field

I've got this model: class Visit(models.Model): timestamp = models.DateTimeField(editable=False) ip_address = models.IPAddressField(editable=False) If a user visits multiple times in one day, how can I filter for unique rows based on the ip field? (I want the unique visits for today) today = datetime.datetime.today() yesterd...

SELECT DISTINCT and ORDER BY

If I place DISTINCT keyword i get an error other wise it is working fine. ERROR: Msg 145, Level 15, State 1, Procedure SP_Products_GetList, Line 15 ORDER BY items must appear in the select list if SELECT DISTINCT is specified. ALTER PROCEDURE [dbo].[SP_Products_GetList] @CatID int, @CatName int, @IsNew bit, @InActive bit, @SortBy ...

Return distinct and null records from a mysql join query

Is there any way to return distinct values with blank/null data from a table join. Best to explain with my example below. Table "orders" order_id | order_total 1 | 10 2 | 20 3 | 50 Table "order_items" item_id | order_id | name | qty_ordered | base_price | row_total 1 | 1 | Product | 1 ...

SELECT DISTINCT and count

Hello, the table looks like this: tag | entryID ----+--------- foo | 1 foo | 2 bar | 3 And now i want to get all tags with its usage: foo | 2 bar | 1 How can I do this? Thank you ...

GROUP BY shows all distinct columns

mysql> select * from products; +---------+-------------+-----------+------+ | prod_id | prod_source | prod_type | flag | +---------+-------------+-----------+------+ | 1 | USA | 2 | 0 | | 2 | USA | 2 | 0 | | 3 | USA | 2 | 0 | | 4 | USA | 3 |...

mysql distinct value for count

I am all over the place here. The MySql query below works for me except for two issues. 1) I want to make sure that only one result per category is displayed (I have 5 categories), I tried using DISTINCT but have clearly misunderstood that one. 2) I want to be able to return the howmany value outside the sql query: "SELECT DISTINCT ca...

SQL order by query

I'm working on a TV guide pagination script - the basic pagination function works properly, no issues there. This is my current SQL query: $result = mysql_query("SELECT programme, channel, airdate, expiration, episode, setreminder FROM mediumonair ORDER by airdate"); However, there's two issues with this script that I'm having troub...

Distinct nodes on multiple keys with XSLT

Hello, i would like to get distinct nodes from my xml on multiple levels. Can anyone please give me some hints how to do this? The methods i googled (Muenchian method, for-each-group) were explained with single grouping keys and plain hearchie. Here's an example of my xml: <persons> <person> <name>Tom</name> <age>20</age> <mail...

PostgreSQL: custom logic for determining distinct rows?

Here's my problem. Suppose I have a table called persons containing, among other things, fields for the person's name and national identification number, with the latter being optional. There can be multiple rows for each actual person. Now suppose I want to select exactly one row for each actual person. For the purposes of the applicat...

JPA - getting distinct value from one column

I have an entity that has few fields. One of them is city name. Now I want to get list of all distinct cities from that table. How can I archive that. I tried using DISTINCT keyword, but it doesn't work. I'm using Hibernate as JPA provider but I would like to get it in pure JPA Query. ...

Finding The Max of sum of elements in matrix in distinct rows and columns

Hi, I have a nxm matrix and I need to find the maximum of sum of its values in distinct rows and columns. For example considering the following Matrix: m1 m2 m3 n1 1 2 3 n2 4 5 6 n3 7 8 9 n4 10 11 12 The max will be 12+8+4 = 24 Note that finding the max and eliminating all values belonging to that column or ...

Left join with distinct values from second table

I'm trying to join two tables, one is a table of tags, and another is a table that bridges tagID and slotID. I want to create a sproc that returns the list of tags, and a column of slots that use those categories. tagDetails tagID tagDescription 1 red 2 blue 3 green 4 purple tagBridge tagID slo...

How to retrieve distinct values from more than one column?

I have two columns of data. I'd like to run select statement on them that grabs all the distinct pieces of data in these columns 1 time. For instance. *column 1* *column 2* dog monkey monkey elephant dog monkey I wanna be able to returna result set that has dog, monkey and elephant in it and that's all. ...

Take count of unique values within distinct codes (XSLT 1)

Hi all, Stuck a bit with the following and would love some ideas/pointers in the right direction. I have the following XML: <RecordsCollection> <CustomerRecord> <customerId>12345</customerId> <currency>USD</currency> </CustomerRecord> <CustomerRecord> <customerId>12345</customerId> <currency>USD</currency> </Cus...

How can I get distinct values using Linq to NHibernate?

Hello, I've been trying to get distinct values using Linq to NHibernate and I'm failing miserably. I've tried: var query = from requesters in _session.Linq<Requesters>() orderby requesters.Requestor ascending select requesters; return query.Distinct(); As well as var query = from requesters in _session.Linq<Reques...

What are the "best practices" to remove "non-unique" values from HUGE table?

Step 1: Loading data via "bulk insert" from .txt (delimited) file into Table 1 (no indexes etc.) bulk insert Table_1 from '\\path\to_some_file.txt' with ( tablock, FORMATFILE ='format_file_path.xml') Via format file I map output Column data types to avoid further conversions (from Char to Int for example) Step 2: OUTPUT the result (...

Select Distinct for 2 columns in SQL query

If I have a table such as 1 bob 1 ray 1 bob 1 ray 2 joe 2 joe And I want to select distinct based on the two columns so that I would get 1 bob 1 ray 2 joe How can I word my query? Is the only way to concatenate the columns and wrap them around a distinct function operator? ...