distinct

How to append distinct records from one table to another

How do I append only distinct records from a master table to another table, when the master may have duplicates. Example - I only want the distinct records in the smaller table but I need to insert/append records to what I already have in the smaller table. ...

SELECT DISTINCT values after a JOIN

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 ...

SQL Select Into Field

I want to accomplish something of the following: Select DISTINCT(tableA.column) INTO tableB.column FROM tableA The goal would be to select a distinct data set and then insert that data into a specific column of a new table. ...

MySQL: Select distict field, but get the rest of the columns as well?

I want to select distinct product_series, but I want all the other columns too. This is my query as it stands: SELECT DISTINCT product_series FROM cart_product WHERE product_brand = "everlon" AND product_type = "ring" AND product_available = "yes" But this only gives me product_series, but I need all the other columns in that row...

Percentage of results that have a column in SQL

I am trying to get a results that will show Uniuque "Reasons", the number of them there are, and the percentage of the total that they are. so far I have SELECT DISTINCT Reason, COUNT(Reason) AS Number, CAST(COUNT(Reason) AS float) / CAST(COUNT(*) AS float) AS percentage FROM DeletedClients However as I have discovered...

is dinstinct an expensive query in django?

Hi, I have three models: Product, Category and Place. Product has ManyToMany relation with Category and Place. I need to get a list of categories with at least on product matching a specific place. For example I might need to get all the categories that has at least one product from Boston. I have 100 categories, 500 places and 100,000...

ordered SQL Select columnwise distinct but return of all columns

I have a little SQL Distinct puzzle that i cannot solve (or at least not in an very elegant way). I have two tables (try to ignore the simplicity of the example). I'm using MSSQL 2008 if that makes much of a difference. Table: Category | categoryId (uniqueidentifier) PK | | Name varchar(50) | Table: Download | do...

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

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 = Det...

Select distinct records on a join

I have two mysql tables - a sales table: +----------------+------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +----------------+------------------------------+------+-----+---------+-------+ | StoreId | bigint(20) unsigned | NO ...

LINQ to XML perform distinct and join between files

Hello all, I am working with some large XML files using LINQ to XML. Now, a typical XML file returns: ID Name Image URL I get a lot of duplicate information, I consider duplicate information to be data with the same ID ( it could have different a name and images and I don't mind). I want to distinct the values of the first XML file ...

Linq Distinct based on property of object

Is it possible to get the distinct elements of a List based on a property of the objects in the List? Someting like: Distinct(x => x.id) What's not usefull for me is following: .Select(x => x.id).Distinct() because then I would get back a List<int> instead of List<MyClass> ...

Group by and non distinct columns and data normalization

Hello Everybody!! I have a large table(60 columns, 1.5 million records) of denormalized data in MS SQL 2005 that was imported from an Access database. I've been tasked with normalizing and inserting this data into our data model. I would like to create a query that used a grouping of, for example "customer_number", and returned a re...

Xsl: Grouping and removing duplicate items

Given the following XML: <interface name="Serial1/0"/> <interface name="Serial2/0.0"/> <interface name="Serial2/0.1"/> <interface name="Serial3/0:0"/> <interface name="Serial3/0:1"/> I am trying to produce the following output: <interface name="Serial1/0"> <unit name="Serial1/0"/> </interface> <interface name="Serial2/0"> <unit n...

How to solve XML to XML problem using Exslt - set:distinct

This extends from http://stackoverflow.com/questions/2133459/xml-to-xml-using-xsl-problem I managed to import exslt and modified my codes according to the solution (thanks to Kyle Butt) given as follows: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:func="http://exslt....

SQL: How to select highest PK out of multiple records returned

Hello all, I have a Journal_Entry table, with a Primary Key of Journal_Entry_ID, and (among other columns) an Entry_Date column. I'm trying to do a query that selects the most recent Entry_Date -- via a SELECT MAX(Entry_Date) -- but the problem is that the user may have logged more than one entry on a given date. So if the user logged ...

Distinct one column and display other columns below

I am sure I am looking at this in the wrong way. I would like to hold a restaurant menu in a database and display it. For example, I have created a table similar to the one below: Columns: Food_Item | Food_Description | Food_Price | Food_CAT. Data: Salad | Refreshing Salad | 5.25 | Starters Prawn Cocktail | Lovely Prawns | 4.75...

Select Count(Distinct Value) returns 1

I'm designing a query in SSMS 2005 which looks something like this: SELECT COUNT(DISTINCT ColumnName) FROM Table WHERE ColumnName IS NOT NULL When I run the query with COUNT() it returns the value 1. When I run it without COUNT(), SSMS reports the correct value eg 212 records. The column in question is of datatype numeric(16, 0). Fo...

SQL Query - one column must be distinct, restricted column must be most recent

Hey there, I have a CATEGORIES table that links to an ITEMS table (one to many). Each item table could have multiple barcodes in the BARCODES table (one to many). The idea is that a new barcode may be added against an item at some point, but the old data is stored in the BARCODES table so that if a search is done with an order with las...

How to go from list of words to a list of distinct letters in Python

Using Python, I'm trying to convert a sentence of words into a flat list of all distinct letters in that sentence. Here's my current code: words = 'She sells seashells by the seashore' ltr = [] # Convert the string that is "words" to a list of its component words word_list = [x.strip().lower() for x in words.split(' ')] # Now conver...

SQL Server select distinct hell

Hi there, I'm stuck on a problem with sql. I have a table with many duplicate entries with column names like:- eventnumber housenumber value1 value2 None of these column names are the primary key as there are many duplicates. What I would like to do is select into another table by distinct housenumber but I seem to get the whole tabl...