distinct

XQuery distinct values with where clause problem

Hi I'm very new to XQuery so excuse me if I am somehow missing something. I am trying to extract data where certain sub-nodes of an element are DISTINCT, as well as where a certain sibling node's is equal to some predefined string for $product in fn:distinct-values(document('cpwdoc')/root/package/properties/value[@key="product"]) wher...

select unique items with linq

When I use the following code I get the same items multiple times. XElement neededFiles = new XElement("needed", from o in _9nFiles.Elements() join t in addedToSitePull.Elements() on o.Value equals t.Value where o.Value == t.Value select new XElement("pic", o.Value)); I'd like to get only unique items...

unique field from mysql database to php

I have a sample database like this, in which, id is always unique, but the user_id is not unique. id,user_id,message,msg_datetime 111,u1, msg from u1,time present here 112,u2, msg from u2,time present here 113,u3, msg from u3,time present here 114,u2, msg from u2,time present here 115,u7, msg from u7,time present here 116,u2, msg from u...

Building a select distinct on mysql ( zend_db)

I HAVE THE FOLLOWING TABLE, I WOULD LIKE TO GET to do a select distinct on the the column [code], i don't need to get the "A" three times. [ ID ] [ CODE ] [ LIBELLE ] 1 A LIBELLE1 2 B LIBELLE2 3 C LIBELLE3 4 A LIBELLE4 5 A LIBELLE5 6 D LI...

Eliminate duplicate data

Query SELECT ppc.personid, ppc.category, ppc.phonenumber, ppc.createts FROM person_phone_contacts ppc WHERE CURRENT_TIMESTAMP BETWEEN ppc.createts AND ppc.endts AND CURRENT_DATE BETWEEN ppc.effectivedate AND ppc.enddate ORDER BY ppc.personid, ppc.category, ppc.createts DESC Resulting Data 3742 | Home | xxx-xxx...

MySQL order by COUNT DISTINCT

Hello I have a sql table: 2.8.7 2.8.3 2.8.2 2.8.7 2.8.5 2.8.7 2.8.7 2.8.5 2.6.0 2.8.3 2.6.4 2.6.3 2.8.4 2.8.0 2.6.3 2.8.5 2.8.5 2.8.5 2.6.0 2.8.2 How do I bring a unique value version sorted by the number of these versions? At the exit I want to get the following: 2.8.5 5 2.8.7 4 2.6.0 2 2.6.3 2 2.8.2 2 2.8....

Distinct values in Android ExpandableListView

Hi all, I'm having trouble with an ExpandableListView. What I want is for each group to be from column "bond", which is non-unique, but I want the groups to be unique (i.e. each value of "bond" should only have one group). Each value in the group has data in other columns which should be displayed. The problem is that it seems I can eit...

Selecting 2 distinct rows MySQL

I have a table called categories that has 3 columns: id, name, parent_id. ID name group_id == == == 1 haim 1 2 gil 2 3 alon 1 4 idan 1 5 shai 3 6 adi 2 7 itay 3 8 aviram ...

SQL - Distinct on two columns and summarized values on third

Hi! I have a table with 3 different IDs. I want to distinct on column 1 and 2 and summarize the values of column 3 (into one field - maybe comma separated string). The summarized field doesn't have to "look nice" (no problems with: '4,3,' (comma at the end)). I'm using MS SQL Server 2008. E.g: ID1 ID2 ID3 1 1 5 1 1 8 ...

count concatenate column in mysql

I want do like this, but for another case that not function. This is my example table: Date Model No Line Range Lot Status 2010-08-01 KD-G435 1 01 1-100 013A accept 2010-08-01 KD-G435 2 01 1-100 013A accept 2010-08-01 KW-TC800 ...

How can I combine sql aggregate functions with distinct more cleanly?

I've been running into the following case repeatedly lately, either I need to apply MAX() or SUM() to one column on a table, but I need DISTINCT sets of values for other columns. For example consider the following table and associated columns representing details of a login to StackOverflow. SoUserLogins (OpenIdToken, Name, IpAdress, L...

Select DISTINCT from multiple columns of multiple tables with PHP and MySQL

Using PHP and MySQL I'm trying to get all the distinct values out the number and type columns from all 4 of the tables listed below: table_1 ID|t1_number|t1_type 1|1|new 2|1|old 3|2|new 4|3|new 5|1|old table_2 ID|t2_number|t2_type 1|1|future 2|1|new 3|3|past 4|3|new 5|1|new table_3 ID|t3_number|t3_type 1|1|past 2|1|new 3|1|new 4|1|...

INNER JOIN DISTINCT with MySQL

I have a mysql problem. I have two tables like this that I need to join together. table: id otherid2 1 | 1 2 | 1 3 | 2 4 | 2 table2: otherid otherid2 1 | 1 2 | 1 3 | 2 4 | 2 I'm using: SELECT id,otherid FROM table INNER JOIN table2 ON table.otherid2=table2.otherid2 Th...

How can I make a searchlogic named scope return DISTINCT (non duplicates?)

I have a searchlogic that searches for not_null on an association that can occur many times, but I only want to display one UNIQUE/DISTINCT instance of the object: Company.contact_emails_id_not_null I only want one Company, no matter how many contact_emails are associated to that Company :through => :contacts ...

How can one inject the sqlite3 keyword DISTINCT into an Android ContentProvider's query?

I have a SQL statement that I can use to return distinct rows from my Android sqlite3 database and I would like to pass it through the ContentProvider's query. For example: select lastName from peopleTable where upper(lastName) like upper("%smith%"); needs to be select DISTINCT lastName from peopleTable where upper(lastName) like up...

Using a DISTINCT clause to filter data but still pull other fields that are not DISTINCT

I am trying to write a query in Postgresql that pulls a set of ordered data and filters it by a distinct field. I also need to pull several other fields from the same table row, but they need to be left out of the distinct evaluation. example: SELECT DISTINCT(user_id) user_id, created_at FROM creations ORDER BY crea...

how do i combine two selects from one table where one has a GROUP BY and the other has a DISTINCT

Both of these work individually SELECT PONumber, count(RequestNumber) as "InNumOfRequests", sum(Amount) as "SumofAmounts" FROM tableView GROUP BY PONumber SELECT DISTINCT PONumber, (10 * ceiling((DATEDIFF(day,POApprovedDate,GETDATE()))/10)) AS "BINofDaysSincePOApproved" ...

Need help on MySQL DISTINCT+COUNT query

I have a table called "r", inside that table I store id, ip, and country. I am running this query: SELECT r.country, count(rr.ip), count(DISTINCT rr.ip) FROM `r` LEFT JOIN r rr ON r.country = rr.country GROUP BY r.country I do get rows with columns: "country";"number";"number"; But both "counts()" doesn not show what I want it to...

[PostgreSQL] How to select distinct from multiple columns

Hi I'm sure there's query for this kind of operation, but I just can't seem to get it. I have a table like this: product_id | saved_by | deleted_by | accepted_by | published_by -----------+----------+------------+-------------+------------- 1 | user1 | | user1 | -----------+----------+------------+---------...

HOWTO get distinct characters of string column in mssql

hy there! given: | name -+--------------------------- | Josef Knoller | Josef Somos | KFZ Wiesauer wanted result: JOSEFKNMLRZWIAU (case in the result does not matter - it was just easier holding the UPPER key while writing) is there any way to do this in mssql? thanks in advance! EDIT sorry ... i've mixed column and row ......