473,386 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

count distinct columns

Hi trying to find the number of duplicate tuples/records in table based on multiple columns ie.

select count(distinct list multiple column key )
from x
where date = y
HAVING ( COUNT(multiple column key) > 1 )

doesn't seem to work....any tips? thanks
Oct 18 '06 #1
4 12306
miller
1,089 Expert 1GB
Hi trying to find the number of duplicate tuples/records in table based on multiple columns ie.

select count(distinct list multiple column key )
from x
where date = y
HAVING ( COUNT(multiple column key) > 1 )

doesn't seem to work....any tips? thanks
Yes, one easy flaw in that statement is that you should make an alias for the COUNT, as you cannot employ the use of COUNT's in a HAVING clause. Additionally you should look into using a GROUP BY. I leave it up to you to look up the syntax for that keyword..

Expand|Select|Wrap|Line Numbers
  1. select count(distinct list multiple column key ) AS myCount
  2. from x 
  3. where date = y 
  4. HAVING myCount > 1
Oct 18 '06 #2
thanks but still doesn't work I have been trying the following:
Expand|Select|Wrap|Line Numbers
  1. select count(distinct id, product_id ) AS myCount
  2. from prd_bal
  3. where date = '30-jun-2006'
  4. HAVING myCount > 1
Oct 19 '06 #3
miller
1,089 Expert 1GB
The below query will return all (id, product_id) combinations that match more than 1 record. This may not be the best method for your problem, but it's one that I know will work based on what you've told us so far.

Expand|Select|Wrap|Line Numbers
  1. SELECT id, product_id, COUNT(*) AS myCount
  2. FROM prd_bal
  3. WHERE date = '30-jun-2006'
  4. GROUP BY id, product_id
  5. HAVING myCount>1;
Note:
"id" is traditionally used as the primary key for most tables. If this is the case for "prd_bal", and it is unique (I would hope), then the above query will return no results. This should get you where you want to go though.
Oct 19 '06 #4
select count(distinct column1 || column2 || column3) cnt from <tablename> where blah blah...
Mar 5 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Dean | last post by:
I want to build query to return how many rows are in this query: select distinct c1, c2 from t1 But SQL won't accept this syntax: select count (distinct c1, c2) from t1 Does someone know how...
0
by: puskas | last post by:
I'm trying to make a report of users per hour (I have one that works for users per day) but when I execute the query I realize that I get more users than the ones I have here is my query ...
2
by: Michael Howes | last post by:
I have a single DataTable in a DataSet. It has 4 columns and i'd like to get a handful of counts of unique items in 3 of the 4 columns. Can a DataTables Select or Compute methods to COUNT DISTINCT?...
2
by: vvyshak | last post by:
Hi all... I have a table in which some columns has distinct values and some has duplicates..i wan to select all the columns with distinct values....no problem if rows has null value in it....i...
1
by: jerry.ranch | last post by:
I see that Access 2003 doesn't support count distinct?? I have a work around, but one statement would be preferably of course Jerry
1
by: aps786 | last post by:
Hi, There is a table where I store ipaddress and user who logged in from that IP. I have a query to findout all ipaddresses, from where diff users had made request. stat ------------ ip...
1
by: dukefrancis | last post by:
Can anyone tell me how to find the count of columns from a table????
4
by: tom booster | last post by:
Hi All, I'm trying to convert a T-SQl query to DB2. I have two tables policy and policyHolder. I would like a count of the amount of distinct poicyHolders per policy, for a particular set of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.