
Second, you need to determine which row among duplicates that you are interested in (or get a random one). This is exactly the same as your GROUP BYdoes, so distinct is redundant. INNER JOIN ArchiveCatalogues ON (ArchiveCatalogues.ARTIST = artist.surname)ĪND (ArchiveCatalogues.FIRSTNAME = artist.firstnames)įirst (common misunderstanding), distinct is not applied to individual columns, what you get is distinct rows. Here is the code: SELECT DISTINCT artist.ArtistID I used DISTINCT on the artist.ArtistID field, but to no avail.

The query below is pulling every result from the ARCHIVESCATALOGUE table, i.e. So I need a query which INNER JOINs the two tables. I want to generate a query which will give me all of the detail from the ARTISTS table, and include an image (does not matter which one) from the other table for each of the artists.
SQLITE COUNT DISTINCT LINE FULL
I have another table ( ARCHIVECATALOGUES), full of auction results, which have the images I need. (For one value this is 1 + 1 - 1) For three rows with two values this gives (1 + 2 - 1 or 2 + 1 - 1)Īlthough the anwer is late, others searching and finding this thread might find this solution usefull.I have two tables, one ( ARTISTS) with a list of different artists, details and biographies, but no images. This 'constant' is one more than the number of distinct values.
SQLITE COUNT DISTINCT LINE PLUS
+ dense_rank() over (partition by cat order by id desc)įROM + dense_rank desc gives the position from the 'start' plus the position from the end, for a given set this gives a 'constant'. , dense_rank() over (partition by cat order by id) SELECT -DISTINCT - Distinct can be switched on / off. Get a count of distinct id's partitioned by cat. I was looking for a similar question and found: DECLARE TABLE (cat CHAR(1), id TINYINT, rw TINYINT) On a side note.why can't you post DR*P TABLE or UNION SELECT anymore.or is that just me. , MAX(rw) OVER (PARTITION BY cat) as maxRw , DENSE_RANK() OVER (PARTITION BY cat ORDER BY id) as catDenseRank , MAX(catDenseRank) OVER (PARTITION BY cat) AS idCount INSERT INTO SELECT 'C' as cat, 5 as id, 3 as rw INSERT INTO SELECT 'C' as cat, 3 as id, 2 as rw INSERT INTO SELECT 'C' as cat, 4 as id, 1 as rw INSERT INTO SELECT 'B' as cat, 2 as id, 4 as rw

INSERT INTO SELECT 'A' as cat, 4 as id, 4 as rw INSERT INTO SELECT 'A' as cat, 3 as id, 5 as rw INSERT INTO SELECT 'A' as cat, 3 as id, 1 as rw I know this worked for me, but is it a valid solution?ĭECLARE TABLE (cat CHAR(1), id TINYINT, rw TINYINT) What if you used a DENSE_RANK instead of a count (ordering by the columns you want a distinct count on) then wrapping that query with a select that grabs the MAX value of the DENSE_RANK. How then can you do this under SQL 2008R2?

Is there a way to do the equivelant in T-SQL for SQL Server 2008R2? I've tried the above and it errors out under SQL 2008R2 and examplce C above is NOT in the same Microsoft article when you change the platform to SQL 2008R2 so I'm assuming this is a feature nehancement in SQL 2012. This is using the DISTINCT keyword so as to get a distinct count where as without it the Count() coould be over stated by the number of rows retruend by the other tables in the join. ON eph.BusinessEntityID = edh.BusinessEntityID JOIN HumanResources.EmployeeDepartmentHistory AS edh In the below Example (from example C in the above Microsoft Document on T-SQL) it shows that you can do the followingĬOUNT(edh.BusinessEntityID) OVER (PARTITION BY edh.DepartmentID) AS EmployeesPerDeptįROM HumanResources.EmployeePayHistory AS eph
SQLITE COUNT DISTINCT LINE WINDOWS
I'm using the Windows functions (as opposed to old fashion aggregation with GROUP BY) because I need both aggregate data and non-aggregated data to be included in the results. I'm trying to get a unique count of rows in a child table in a multi-table join just like the example shown below from the above Microsoft article on COUNT().
