distinct

PostGres Error When Using Distinct : postgres ERROR: could not identify an ordering operator for type record

这一生的挚爱 提交于 2019-12-05 22:41:14
** EDIT ** Nevermind, just needed to take out the parens... I get this error: ERROR: could not identify an ordering operator for type record when trying to use DISTINCT Here's the query: select DISTINCT(g.fielda, g.fieldb, r.type) from fields g LEFT JOIN types r ON g.id = r.id; And the errors: ERROR: could not identify an ordering operator for type record HINT: Use an explicit ordering operator or modify the query. ********** Error ********** ERROR: could not identify an ordering operator for type record SQL state: 42883 Hint: Use an explicit ordering operator or modify the query. As I think

Django ModelChoiceField using distinct values from one model attribute

99封情书 提交于 2019-12-05 19:17:32
so I'm working on a django application where I have a model Event. Each Event has some attributes, say one of them is "hostname" (which I will use throughout as an example). I need to implement search functionality where a user can search for all events that has hostname == some_value, e.g. hostname == "myhost.foo.bar". Now, I wanted to allow the user to select among the valid options (i.e. the hostnames that actually exist in one or more event) in a combobox in the search form, so I use ModelChoiceFields for my form. My subclass of ModelChoiceView, for displaying the correct label: class

Rails 3.1 distinct find and missing attributes

眉间皱痕 提交于 2019-12-05 16:19:02
class State < ActiveRecord::Base has_many :cities end class City < ActiveRecord::Base belongs_to :state has_many :companies end class Company < ActiveRecord::Base belongs_to :city end I'm trying to list all states, and their respective cities, that contain at least one company registered. My first try was the following query: states = State.joins(:cities => :companies).includes(:cities) Which works, but I end up getting duplicates if a state has more than one city with companies in it. I then changed the query to: states = State.joins(:cities => :companies).includes(:cities).select("distinct

SQLite outer query is returning results not found in inner query

我是研究僧i 提交于 2019-12-05 15:26:28
I just wondered if anyone has run into a case in SQLite (3.7.4) where a query would return one set of results, and when it becomes a subquery the results are completely different? I found the problem in a more complex query, but here's a simpler example that demonstrates the same behavior: Database setup: CREATE TABLE "test" ("letter" VARCHAR(1) PRIMARY KEY, "number" INTEGER NOT NULL); INSERT INTO "test" ("letter", "number") VALUES('b', 1); INSERT INTO "test" ("letter", "number") VALUES('a', 2); INSERT INTO "test" ("letter", "number") VALUES('c', 2); Initial query: SELECT "letter", "number"

LINQ to Objects .Distinct() not pulling distinct objects

孤街醉人 提交于 2019-12-05 15:15:16
I have two ways that I am doing a fuzzy search for a customer. One is by an abbreviated name and the other is by the customer's full name. When I take these two result sets and then union them together (which I have read several places should remove distinct values) I get duplicates. Thinking that all I need to do is then call the .Distinct() method on this, I also still get duplicates. Do I need to implement some compare functionality in my customer object? My code: Dim shortNameMatch As List(Of ICustomer) = CustomerLibrary.GetCustomersByShortName(term) Dim custNameMatch As List(Of ICustomer)

SELECT DISTINCT values after a JOIN

女生的网名这么多〃 提交于 2019-12-05 11:53:01
I have 3 tables: Vehicle: vehicle_id, vehicle_type 1, motorcycle 2, car 3, van Owners: person_id, vehicle_id, date_bought 1, 1, 2009 1, 2, 2008 2, 3, 2009 2, 1, 2005 I want to display a list of all vehicle names. If the person_id = 1 , date_bought should also be returned. So I thought I would start with this: SELECT * FROM vehicles LEFT JOIN Owners USING (vehicle_id) which returns this: 1, 1, motorcycle, 2009 1, 2, car, 2008 2, 3, van, 2009 2, 1, motorcycle, 2005 However, I now cannot narrow this down to the needed result. If I use DISTINCT(car_id) , there is no change as I am already choosing

NHibernate: Get distinct results based on a column, but retrieve all columns

谁说胖子不能爱 提交于 2019-12-05 07:59:00
I have a table GL that contains GLCode. I need to get a list of unique GLCodes, but get all the other columns. The following SQL produces the results I want. select * from GL where GLId in (select Min(GLId) from GL group by GLCode ) Is there a way to do this using the Criteria API? This is my best attempt: var subQuery = DetachedCriteria.For<GL>(); subQuery .SetProjection(Projections.Property("GLCode")) .SetResultTransformer(new DistinctRootEntityResultTransformer()); return (List<GL>)currentSession .CreateCriteria(typeof(GL)) .Add(Subqueries.PropertyIn("GLCode", subQuery)) .List<GL>(); Even

Finding distinct values of non Primary Key column in CQL Cassandra

寵の児 提交于 2019-12-05 05:39:04
I use the following code for creating table: CREATE KEYSPACE mykeyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 }; USE mykeyspace; CREATE TABLE users ( user_id int PRIMARY KEY, fname text, lname text ); INSERT INTO users (user_id, fname, lname) VALUES (1745, 'john', 'smith'); INSERT INTO users (user_id, fname, lname) VALUES (1744, 'john', 'doe'); INSERT INTO users (user_id, fname, lname) VALUES (1746, 'john', 'smith'); I would like to find the distinct value of lname column (that is not a PRIMARY KEY). I would like to get the following result: lname -------

mysql DISTINCT语句 语法

浪子不回头ぞ 提交于 2019-12-05 04:03:01
mysql DISTINCT语句 语法 作用: 用于返回唯一不同的值。 语法: SELECT DISTINCT 列名称 FROM 表名称。 扬州大理石量具 mysql DISTINCT语句 示例 //从表中选取唯一不同的值 SELECT DISTINCT 列名称 FROM 表名; 来源: https://www.cnblogs.com/furuihua/p/11904491.html

How to select part of a Timestamp in a SQL Query

旧街凉风 提交于 2019-12-05 02:07:55
In the DB I am working with, I want to select only the year from a specific TimeStamp field. In particular, I'm hoping to select the unique years from this database column. For instance, if all of the timestamps in the field "ModifyTimeStamp" are either from the year 2002 or the year 2006, I would like returned simply a result of '2002' and '2006'. If this is impossible, I'd be content with getting a result of a bunch of '2002's mixed with '2006's and would parse it later. All I've been able to get working so far is "Select ModifyTimeStamp from Table" - all my attempts to parse have failed. I