Select distinct...again
I have data that contains a column of emails, a column of
names and
addresses... and so on.
some of the emails are the same and I don't want those to
show up.
I want to be able to pull a column of emails, a column of
names and a
column of adresss but I want to pull only those that have
distinct email
addresses.
When I
SELECT Distinct email, FName, LName
FROM table1
WHERE (MailList = 1)
It doesn't filter out the distinct. I'm guessing that you're
going to
say it's pulling from the row...
How would I make it so that I only see rows with distinct
emails?
Thanks
Lionstone?
Philo wrote:
> for MSSQL: The DISTINCT keyword is optional with SUM,
AVG, and COUNT.
> When DISTINCT is used, duplicate values are eliminated
before the sum,
> average, or count is calculated.
>
> Basically it eleminiates duplicates. That does not seem
to be what you
> are doing. By distinct do you mean none null emails
addresses? If so
> than something like "where email is not null" is what
you want.
>
> Art wrote:
>
>> I have data that contains a column of emails, a
column of names and
>> addresses... and so on.
>>
>> some of the emails are the same and I don't want
those to show up.
>>
>> I want to be able to pull a column of emails, a
column of names and
>> a column of adresss but I want to pull only those
that have distinct
>> email addresses.
>>
>> When I
>>
>> SELECT Distinct email, FName, LName
>> FROM table1
>> WHERE (MailList = 1)
>>
>> It doesn't filter out the distinct. I'm guessing
that you're going to
>> say it's pulling from the row...
>>
>> How would I make it so that I only see rows with
distinct emails?
>>
>> Thanks
>>
>> Lionstone?
It sounds like he wants to email all the unique email
addresses, so
DISTINCT should work as it avoids duplicates.
Maybe try:
SELECT DISTINCT TOP 100 email, FName, LName
FROM table1
WHERE MailList = 1
Steve
Similar Messages
-
Select DISTINCT attribute vlaues fom XMLTYPE column and...
Hello
I have spent whole day to find the solution with no success. PLEAS HELP !
The Problem :
1. I have table with xmlType column in this column is the following xml:
<revision>
<product id = 1>
<screw>
<img id = 1/>
</screw>
<screw>
<img id = 2/>
</screw>
</product>
<product id = 2>
<screw>
<img id = 1/>
</screw>
</product>
</revision>
I must select DISTINCT img IDs and then select/join them form relational table img (id(number), pic (blob) )
I can't find the solution to select distinct attribute values from XML!
I have tried this:
select extract(c.xml, 'revision/product/screw/img[not(@id=preceding-sibling::img/@id)]/@id') from TABLE c;Hello Odie_63
I have again problem finally my XML looks that:
<revision>
<product id = "1">
<screw>
<img id = "1"/>
</screw>
<component>
<img id = "1"/>
</component>
<screw>
<img id = "2"/>
</screw>
<component>
<img id = "2"/>
</component>
</product>
<product id = "2">
<screw>
<img id = "1"/>
</screw>
<component>
<img id = "4"/>
</component>
</product>
</revision>'));
And I don't know why my following statement doesn't work. (I must slect all distinct id from <img>).
select distinct x.img_id
from cfg_xml t
, xmltable(
'/revision/definitions/product'
passing T.EQ_CFG_XML
columns img_id number path '/component/img/@id',
img_id2 number path '/screw/img/@id'
) x
And this is VERY SLOW :/
select x.img_id, y.img_id
from cfg_xml t
, xmltable(
'/revision/definitions/product/screw/img'
passing T.EQ_CFG_XML
columns img_id number path '@id'
) x,
xmltable(
'/revision/definitions/product/component/img'
passing T.EQ_CFG_XML
columns img_id number path '@id'
) y
Is it possible to return al distinct ID in one column>?
Thanks for HELP :)
Edited by: kozand on 2011-06-29 07:50 -
This is sort of related to another issue that's been posted on this message board.
As a temp fix, I'm trying to have my Results page pull in a bunch of products from a Products table. .
I have another table of Warnings that get joined by the product ID
The Warnings table will have multiple items with the same part number (different warning IDs)
So, when I pull in the products, I get multiples of the same products
I've tried a number of different methods to get this not to pull in multiples:
I've tried DISTINCT just on products
I've tried a subquery using DISTINCT the WHERE statement
DISTINCT just doesn't want to work and I've read it's not exactly the best way to do it.
How else can I do it?
Below is basically how I've tried to do it.
SELECT P.ID, HAZ.PID, HAZ.hazardID
FROM tblProducts P
LEFT OUTER JOIN tblHazard HAZ ON P.ID = HAZ.PID
WHERE (HAZ.PID IN (SELECT DISTINCT PID FROM tblHazard sHAZ))I want multiple rows but not duplicates.
Lets say I have 7 different partnumbers but in this database I have some that have multiples of the same part number. However, Instead of seeing part numbers:
1,2,2,3,4,5,5,6,7
I want to see part numbers:
1,2,3,4,5,6,7
The ONLY way I know to fix this is to use DISTINCT but that only works if all the matching rows that have duplicates are exactly the same. In my case, the hazDate and the ID and hazID will be different so they will be DISTINCT. Therefore, I would, no doubt, get "duplicates."
In other words, I want every part number once but no duplicates.
Using this example again:
SELECT DISTINCT PID, hazdate
FROM tblHazard
Above gives me "1,2,2,3,4,5,5,6,7" Since the hazdate/times are different in every row, it sees them as distinct even though product number is the same. The only one I really want to test if it's DISTINCT is the PID. So, when I test DISTINCT on just the PID, it works! Below works.
SELECT DISTINCT PID
FROM tblHazard
Gives me 1,2,3,4,5,6,7
However, as I said above, I need to have the hazDate and hazID available. I run an "If statement." If it's hazID = 1, I show one type of warning and if it's hazID = 4, I show another type.
So, what I need, is a different way to eliminate duplicate part number rows. -
Select distinct record based on column
Hello All,
I have a table that has more than one row as Detail for a single invoice number(screenshot below). When I create report based on this table, I get multiple rows for single invoice. I mean Invoice 000027 shows up with 5 different rows on the SSRS report.
Is there a way I could display a single row for a single invoice? Any thoughts on this will be greatly appreciated. Thanks.
Regards,
Amol
eport )Thank you all for your suggestions. The issue is how can I get single distinct columns after joining 2 tables (InvoiceHeader & InvoiceDetail). I am using following query in my dataset.
SELECT DISTINCT I.recid, I.InvNumber, D.Detail, I.CompanyName, I.Addr1, I.SalesRep, I.JobNumber, I.Status, I.InvDate, I.TotalInvAmount
FROM InvoiceHeader AS I INNER JOIN
InvoiceDetails AS D ON I.InvNumber = D.InvoiceNumber
WHERE (I.InvNumber = @InvoiceNumber) AND (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) OR
(I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (I.JobNumber = @JobNo) OR
(I.InvNumber = @InvoiceNumber) AND (I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status))
AND (@JobNo = '') OR
(I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (I.JobNumber = @JobNo) AND
(@JobNo = '') OR
(I.InvDate >= @StartDate) AND (I.InvDate <= @EndDate) AND (I.CompanyName IN (@Customer)) AND (I.Status IN (@Status)) AND (@JobNo = '') AND
(@InvoiceNumber = '')
ORDER BY I.InvNumber DESC
Thanks again.
Amol -
Query help in select Distinct on one column.
CREATE GLOBAL TEMPORARY TABLE Table1 (
ID1 varchar2(100) ,
Name1 varchar2(100),
Name11 varchar2(100)
insert into Table1 values ('a','n1','h3');
insert into Table1 values('b','n2','h2');
insert into Table1 values('a','n3','h1');
insert into Table1 values('c','n4','h5');
insert into Table1 values ('c','n5','h4');
insert into Table1 values('d','n6','h6');
select * from Table1;
ID1,NAME1, NAME11
a, n1, h3
b, n2, h2
a, n3, h1
c, n4, h5
c, n5, h4
d, n6, h6
I am trying to select distinct ID1 and all values associated with it which is max row.I want to result as -
ID1,NAME1, NAME11
a, n3, h1
b, n2, h2
c, n5, h4
d, n6, h6
Can you please help me to write simple query to get above result.
Edited by: 871447 on Jul 25, 2011 9:42 AM
Edited by: 871447 on Jul 25, 2011 9:45 AMHi,
Do a self-join, to combine the two rows for each value of id1 onto one output row.
Make it an outer join, in case there is only one row with a vlaue for id1.
SELECT l.id1
, l.name1
, NVL ( r.name11
, l.name11
) AS name11
FROM table1 l
LEFT OUTER JOIN table1 r ON l.id1 = r.id1
AND l.name1 < r.name1
;Edited by: Frank Kulash on Jul 25, 2011 12:57 PM
Sorry, I mis-read the problem.
Lee's solution, above, assumes that name1 is unique, as it is in your sample data.
What output would you want if that's not the case?
If name1 is not unique, but the combination of (id1, name1) is unique, then you can modify Lee's solution like this:
SELECT *
FROM table1
WHERE (id1, name1) IN (
SELECT id1
, MAX (name1)
FROM table1
GROUP BY id1
;Or, if you can't make any assumptions about uniqueness, you might need something like this:
WITH got_r_num AS
SELECT id1, name1, name11
, ROW_NUMBER () OVER ( PARTITION BY id1
ORDER BY name1 DESC
, name11 DESC
) AS r_num
FROM table1
SELECT id1, name1, name11
FROM got_r_num
WHERE r_num = 1
; -
After updating AVG anti-virus, I encountered a problem on Firefox. I would select a link from the drop down on the address bar but the page would not open after clicking on it. I would select it again, even double click, but the page does not open. I could only reach website by selecting google or yahoo from my dropdown on the most visited list and then click the website that I want to visit. I would like to do this in one step by just selecting a link from my history on the address bar and select a link instead of going to google and then writing the page I want to visit. What could be the problem? When going to the address bar to select a link to open, why does the site not open? Any help would be appreciated.
Hi,
Please check if this happens in [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode.]
[http://kb.mozillazine.org/Problematic_extensions Problematic Extensions]
[https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
[http://support.mozilla.com/en-US/kb/Uninstalling+add-ons Uninstalling Add-ons]
[http://kb.mozillazine.org/Uninstalling_toolbars Uninstalling Toolbars] -
How to select distinct values from a table when it has composite primary ke
Hi
I have the requirement like , I need to select distinct one column values from the table which has composite primary key. How to acheive this functioinality using view object.
Eg : Table 1 has col1 and col2, col3
col1 col2 col3
1 A NA
1 B NA
2 A NA
3 C NA
2 D NA
primary key (col1,col2)
I have to select distinct col1.
ThanksHi
I got the solution for above. By Creating the read only view object we can acheive this.
thanks -
Need of SQL query in selecting distinct values from two tables
hi,
I need a query for selecting distinct values from two tables with one condition.
for eg:
there are two tables a & b.
in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
can anybody please help me.
Thanks in advance,
RatheeshNot sure what you mean either, but perhaps this will start a dialog:
SELECT DISTINCT a.empno,
a.name,
a.sex,
b.salary,
b.doj
FROM a,
b
WHERE a.empno = b.empno;Greg -
Serious performance problem - SELECT DISTINCT x.JDOCLASSX FROM x
I am noticing a huge performance problem when trying to access a member that
is lazily loaded:
MonitorStatus previousStatus = m.getStatus();
This causes the following query to be executed:
SELECT DISTINCT MONITORSTATUSX.JDOCLASSX FROM MONITORSTATUSX
This table has 3 million records and this SQL statement takes 3 minutes to
execute! Even worse, my app heavily uses threads, so this statement is
executed in each of the 32 threads. As a result the application stops.
Is there any way that I can optimize this? And more importantly, can Kodo
handle a multithreaded app like this with a huge database? I've been having
a lot of performance problems since I've started doing stress & load
testing, and I'm thinking Kodo isn't ready for this type of application.
Thanks,
MichaelYou can prevent this from happening by explicitly enumerating the valid
persistent types in a property. See
http://docs.solarmetric.com/manual.html#com.solarmetric.kodo.PersistentTypes
for details.
>
Inconveniently, this nugget of performance info is not listed in the
optimization guide. I'll add in an entry for it.This setting did in fact prevent the query from running which fixed the
problem. It definitely belongs in the optimization guide.
And more importantly, can Kodo
handle a multithreaded app like this with a huge database? I've beenhaving
a lot of performance problems since I've started doing stress & load
testing, and I'm thinking Kodo isn't ready for this type of application.I'd like to find out more information about details about your issues. We
do a decent amount of stress / load testing internally, but there are
always use cases that we don't test. Please send me an email (I'm assuming
that [email protected] is not really your address) and let's
figure out some way to do an analysis of what you're seeing.This email is just for posting to usenet, to avoid spam. I'm now running my
app through stress/load testing so I hope to discover any remaining issues
before going into production. As of this morning the system seems to be
performing quite well. Now the biggest performance problem for me is the
lack of what I think is called "outer join". I know you'll have this in 3.0
but I'm suprised you don't have this already because not having it really
affects performance. I already had to code one query by hand with JDBC due
to this. It was taking 15+ minutes with Kodo and with my JDBC version it
only takes a few seconds. There are lots of anti-JDO people and performance
issues like this really give them ammunition. Overall I just have the
impression that Kodo hasn't been used on many really large scale projects
with databases that have millions of records.
Thanks for configuration fix,
Michael -
Issue with "Select Distinct" query in Oracle 10g against Oracle 9i
Hi,
I would appreciate if some one help me here because it is really urgent.
We are upgrading our database from 9i to 10g.
There are the "Select distinct" queries in the code which populated the grid on the applications screens. We found a difference in 9i and 10g the way the result is populated for these queries. If "Select Distinct" query wihtout a order by clause is executed in 9i then the result is automatically sorted. But Oracle 10g does not do this.
We can change the queries adding order by clause but we are almost at the end of the testing and want to know if there is any way that we can do this from database settings. Would there be any impact of these settings change on overall operation of Oracle 10g?
I would appreciate if some one can help me here.
Thanks,
Dineshthen the result is automatically sorted.No. Oracle may have done a sort operation to perform the distinct, but it still did not guarantee the order of your results.
In 10g and in 9i, if you want your results in a certain order you must use order by. -
Select Distinct and join in ODI
Hi,
I have following task to perform: I am loading metadata into Planning dimension from Oracle database. I have two tables
1. "Sales"
Columns: Name, Number, Value
Sample Data:
Product 1, 10, 200
Product 2, 30, 100,
Product 1, 15, 500
2. P&R
Columns:
Name, Alias
Product 1, SampleSoda1
Product 2, SampleSoda2,
Resource 1, CanForSoda,
Resource 2, CO2
What I need to do is: I have to select name and alias from second table of all products that were sold.
So I need to select distinct Name from Table 1, naxt join it with Table 2 (so I have Name and Alias) and load it to planning.
I am a little confused how to do it.
Any help would be great!
Best regards,
GregHi Greg,
What you can do is either :
- Create a yellow interface with your table Sales as source. Map the name column directly in the target. In the flow tab, click on your target and select "Distinct rows".
- Create a second interface, with your first interface as source. Select the "Use Temporary Interface as Derived Table (Sub-Select)" checkbox.
- Add your second datastore and join it. Or you can use a lookup table.
OR
- Create an interface with Sales and P&R as source (or set P&R as a lookup table).
- Go on the flow tab and select "Distinct rows".
If you've a lot a data in the first table, I would go for the first solution.
Hope it helps.
Regards,
JeromeFr
Edited by: JeromeFr on Feb 14, 2013 9:52 AM
To be more clear in the first step of solution 1 -
Select distinct for a date column in present. service when creating prompt
hi all
I am trying to create some new prompts in my answers and I have the following problem. When I try to create a new prompt on a date column ( for example Modification Date), when I try to run this report on this prompt it is displaying the same date a lot of times ( for example 2/4/11 it is being displayed 4 times).
Is there any way i can change this, so to display distinct dates?
Thank you and best regardsHi Deva
I am trying to use this, but in the system are being saved the date + hour.
When i try select distinct modification date from My_view, i still have the same dates because they have different hours.
When i try select disctinct to_date(modification_date)..... I am having an error in BI.
Please help me to solve this issue.
Regards -
Select Distinct (More than one column)
Hi All,
I have the following SQL statement written in MySQL that returns only one row per MODCODE with the associated DEPTCODE of AE:
SELECT DISTINCT
EL_MODULE.DEPTCODE, EL_MODULE.MODCODE, EL_MODULE.MODNAME, EL_MODULE.MODLEVEL, EL_DEPTLEVEL.DEPTLEVELHEADER
FROM EL_DEPTLEVEL, EL_MODULE
WHERE EL_MODULE.MODLEVEL = EL_DEPTLEVEL.LEVELCODE AND EL_MODULE.DEPTCODE='AE' ORDER BY EL_MODULE.MODLEVEL
However when I attempt to use this in oracle it returns three rows, could somebody point out what it is I need to change to get this working correctly in oracle.
Hope someone can help.
JonDuplicates? No way! This query returns unique comibination of
EL_MODULE.DEPTCODE,
EL_MODULE.MODCODE,
EL_MODULE.MODNAME,
EL_MODULE.MODLEVEL and
EL_DEPTLEVEL.DEPTLEVELHEADER
Cheers
Sarma. -
When using ‘insert into table2 select distinct field from table1′ and table2 contains a field with a default value sys_guid(), the distinct operator does not seem to work ! This was tested on Oracle 10.2.0.4 on 64 bit linux. See the following SQL code to prove it :
create table table1 (field1 varchar2(100));
insert into table1 (field1) values (‘value1′);
insert into table1 (field1) values (‘value1′);
insert into table1 (field1) values (‘value2′);
– distinct and to_char(sysdate) function gives the correct 2 rows (‘value1′ and ‘value2′)
create table table2 (field1 varchar2(100), field2 raw(16) default to_char(sysdate, ‘hh’));
insert into table2(field1) select distinct field1 from table1;
select * from table2;
rollback;
drop table table2 purge;
– distinct and sys_guid function gives 3 rows (twice ‘value1′ !!) instead of 2
create table table2 (field1 varchar2(100), field2 raw(16) default sys_guid());
insert into table2(field1) select distinct field1 from table1;
select * from table2;
rollback;
drop table table2 purge;
– with group by : no problem
create table table2 (field1 varchar2(100), field2 raw(16) default sys_guid());
insert into table2(field1) select field1 from table1 group by field1;
select * from table2;
rollback;
drop table table2 purge;
drop table table1 purge;It looks like I can reproduce (on XE 10.2.0.1), with or without using a default for sys_guid:
SQL> select banner from v$version where rownum=1;
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
1 row selected.
SQL> create table table1 (field1 varchar2(100));
Table created.
SQL> insert into table1 (field1) values ('value1');
1 row created.
SQL> insert into table1 (field1) values ('value1');
1 row created.
SQL> insert into table1 (field1) values ('value2');
1 row created.
SQL> -- distinct and to_char(sysdate) function gives the correct 2 rows (‘value1' and ‘value2')
SQL> create table table2 (field1 varchar2(100), field2 raw(16) default to_char(sysdate, 'hh'));
Table created.
SQL> insert into table2(field1) select distinct field1 from table1;
2 rows created.
SQL> select * from table2;
FIELD1 FIELD2
value1 11
value2 11
2 rows selected.
SQL> drop table table2 purge;
Table dropped.
SQL> -- distinct and sys_guid function gives 3 rows (twice ‘value1' !!) instead of 2
SQL> create table table2 (field1 varchar2(100), field2 raw(16) default sys_guid());
Table created.
SQL> insert into table2(field1) select distinct field1 from table1;
3 rows created.
SQL> select * from table2;
FIELD1 FIELD2
value1 5AF743C0FD484D578E84276C875C5BC1
value1 725ABE6066BF42E2A78406BD549D9E85
value2 CC43E3C688AF428B885A0F4EA24482CB
3 rows selected.
SQL> drop table table2 purge;
Table dropped.
SQL> -- without using DEFAULT, here Max is right (see posts below)
SQL> create table table2 (field1 varchar2(100), field2 raw(16));
Table created.
SQL> insert into table2(field1, field2) select distinct field1, sys_guid() from table1;
3 rows created.
SQL> select * from table2;
FIELD1 FIELD2
value1 7B277A2068AF468EBC06E33F6700B9E3
value1 9644C1C8A909489F98B51531BDD282D9
value2 8707FD2E6AB94EA7810D8D4AB19AB091
3 rows selected.
SQL> drop table table2 purge;
Table dropped.
SQL> -- with group by : no problem
SQL> create table table2 (field1 varchar2(100), field2 raw(16) default sys_guid());
Table created.
SQL> insert into table2(field1) select field1 from table1 group by field1;
2 rows created.
SQL> select * from table2;
FIELD1 FIELD2
value2 202A87C86EF446D8915B3C976385D68F
value1 484625A675524FA09CC393A78411B38A
2 rows selected.
SQL> drop table table2 purge;
Table dropped.
SQL> drop table table1 purge;
Table dropped.Edited by: hoek on Feb 18, 2010 11:29 AM -
Ora-00600 error on select distinct when using cursors
Hi, we are using oracle9iFS version 9.0.1.1.0. When I execute the following query in sqlPlus an ora-00600 error occurs.
Here is the query:
SELECT DISTINCT ODMV_FOLDER.NAME,
CURSOR(SELECT ODMV_DOCUMENT.NAME
FROM ODMV_DOCUMENT
WHERE ODMV_DOCUMENT.ID = ODMV_FOLDERRELATIONSHIP.RIGHTOBJECT)as Document
FROM ODMV_FOLDER,
ODMV_FOLDERRELATIONSHIP
WHERE ODMV_FOLDER.CREATOR = 96 /*this is the user 'system'*/
AND (ODMV_FOLDER.ID = ODMV_FOLDERRELATIONSHIP.LEFTOBJECT)
I have no clue why is this happening. I might be doing something wrong since a similar query with a nested cursor works with the scott/tiger schema. Your help is greatly appreciated. Thank you in advance.
Alfonso.I was able to reproduce this error. This looks like a bug in the RDBMS; I would suggest posting on their newsgroup or working with support to handle this problem.
Maybe you are looking for
-
Question about recording from VCR to Qosmio
I want to record my old personal Videos from VCR tapes to DVD using my Qosmio F10. I plug the VCR analogue output via a coax cable into the Qosmio TV aerial input and set up the Qosmio to recognize the VCR input as just another TV channel. It records
-
Email message in the body of the email does not appear
The plug to the BBQ appliance under the bench in the alfresco is not compatible can this be checked Glass missing to the canopy when will it be completed
-
Anyone know how to transfer Nokia N8 message to No...
I got my Nokia N8, but all the message I sync into the Nokia Suite. However, I going to buy a Nokia's Windows Phone, how can I transfer all the message to Windows phone from the Nokia Suite? Solved! Go to Solution.
-
Proper Deletion of Records for many to many relationships
Hello Pros, Need advice for best practice on following scenario. This is just an example based on my actual needs. People Table -> PeopleJoinAddress Table-> Address Table 1 | John 1 | 1 1 | Address 1 2 |
-
Windows 7 - Oracle 10.2.0.5 Database Client Installation (32bit)
Where can I get this? I tried installing the 10.2.0.3 client, and the 10.2.0.5 patchset - but that got me nowhere. It seems like the patchset is for the DB server, not the client (unless there is something I am missing due to obtuseness.). Is there a