Select distinct problem

Hi all,
I'm not exactly Mr. Database...but I've been trying to make a
query where I can get all distinct values from one column/field in
my table like so and stick them in variables.. :
<cfquery name="initialValues"
datasource="fikestudioDB">
select distinct aLitho from jobs where aproductID =
#VAL(URL.productID)#
</cfquery>
But what I need to do is store each unique value of the field
"aLitho" into a variables after running the query....
I will usually have about 3-4 unique values in the query.....
but storing them into variables is what I've been trying to do...
Any help is greatly appreciated..
Thanks!

If you guys are still around...
Can someone just explain to me the difference in results
here:
Here is the entire file for testing..... and at this URL...
http://65.36.189.174/test/testoptions.cfm
But, why..... when I print the values.... CF gives me one
instance of each value (how I want it... as seen in the page)....
But Javascript (as seen in the source code)... gives me
duplicate values..?
I wanted distinct values only in the query (which I thought I
was doing ... but JavaScript makes me think twice ..if I am doing
it right..)
Just curious... thanks!
john
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<html>
<head>
<title>Test Options</title>
</head>
<body>
<cfquery name="initialOptionValues"
datasource="fikestudioDB">
select distinct aLitho from jobs where aproductID = 3
</cfquery>
<CFIF initialOptionValues.RecordCount LT 2>
<CFOUTPUT query="initialOptionValues">
<cfset Option1 = #initialOptionValues.aLitho[1]#>
</CFOUTPUT>
<CFELSEIF initialOptionValues.RecordCount GT 1 and
initialOptionValues.RecordCount LT 2>
<CFOUTPUT query="initialOptionValues">
<cfset Option1 = #initialOptionValues.aLitho[1]#>
<cfset Option2 = #initialOptionValues.aLitho[2]#>
</CFOUTPUT>
<CFELSE>
<CFOUTPUT query="initialOptionValues">
<cfset Option1 = #initialOptionValues.aLitho[1]#>
<cfset Option2 = #initialOptionValues.aLitho[2]#>
<cfset Option3 = #initialOptionValues.aLitho[3]#>
</CFOUTPUT>
</CFIF>
<cfoutput>#Option1#</cfoutput>
<cfoutput>#Option2#</cfoutput>
<cfoutput>#Option3#</cfoutput>
<script language="javascript">
var jsTabFour = <cfoutput
query="initialOptionValues">#initialOptionValues.aLitho[1]#</cfoutput>;
var jsTabFive = <cfoutput
query="initialOptionValues">#initialOptionValues.aLitho[2]#</cfoutput>;
var jsTabSix = <cfoutput
query="initialOptionValues">#initialOptionValues.aLitho[3]#</cfoutput>;
</script>
</body>
</html>

Similar Messages

  • Select distinct problem with muliple join tables, help needed

    Hi,
    I have two main tables. Each has its of sub joined tables.
    guest_id_for_reservation connects two major tables. This has
    to be that way
    because my guest may change the room status from single to
    double (and the
    similar exceptional requests).
    guests reservation
    guest_id_for_reservation
    countrytable hoteltable
    delegationtable roomtype
    I form a query. I want to select distinct those results. But
    it does not
    work.
    If I do not include any table related to reservation table
    and its sub
    joined tables (disregarding guest_id_for_reservation), it
    works.
    Is there a specific syntax for select distinct of this type
    or any
    workaround.?
    Thank you
    Hakan

    Hi I'm still battling with this - have connected the AX to my Imac via ethernet and it shows up fine in Airport Utility. Status light is green and it says its set up to connect to my existing wireless network using wireless connection. Security in Network Preferences is the same for both: WPA2 Personal.
    So I don't think there's a problem with the AX, and my current wireless network (BT Home Hub) is working fine.
    And when I restore factory settings Airport Utility can see the AX before updating settings so the wireless side of AX must work too.
    I'm figuring it must be something about the settings that mean AU can't see it anymore. But I can't work out what, since security is the same.
    Any ideas would be great!

  • 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,
    Michael

    You 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

  • SELECT DISTINCT does not work - Another Problem!

    Dear All
    Previous Post
    I just posted a thread, which has been answered by an expert. It's here:
    SELECT DISTINCT does not work. Why?
    My original problem was that the Query returned duplicate records, and SELECT DISTINCT did not work.
    The solution was to change this select:
    T0.[U_SupInv]      AS 'Link'
    ... to this:
    CAST(T0.[U_SupInv] as nvarchar(100))      AS 'Link'
    The amended Query worked.
    New Problem
    I just discovered that resolving the problem created a new one.
    The field U_SupInv (Link) is in fact a UDF.
    I created it so that all Suppliers' Invoices could be Scanned to pdf files, and these pdf could be linked
    to the respective AP Invoice.
    Originally, when I clicked 'Link' in my Query results, the pdf scan pops up.
    When the Query is amended by adding CAST, the link becomes dead.
    Help
    Could anyone tell me how I can make SELECT DISTINCT work, as well keeping the LINKS live?
    The main purpose of my Query is to help users view the pdf scans by clicking on the links.
    Thanks
    Leon Lai
    Here's my Original Query
    SELECT
    T0.[UpdateDate] AS 'Update Dt',
    T0.[TaxDate] AS 'Doc Dt',
    CASE T5.[TransType]
         WHEN '18' THEN 'PU ' + CONVERT(VARCHAR(6), T0.[DocNum])
         WHEN '19' THEN 'PC ' + CONVERT(VARCHAR(6), T0.[DocNum])
    END 'SAP Ref.',
    T1.[ImportLog]     AS 'Ship #',
    T0.[CardCode] + '' AS 'Supplier #',
    T0.[CardName]      AS 'Supplier Name',
    T0.[DocTotal]      AS 'Rs',
    T1.[BlockNum]      AS 'Reqn #',
    T0.[DocNum]        AS 'Doc No',
    T0.[U_SupInv]      AS 'Link'
    FROM klship.[dbo].[OPCH] T0
    INNER JOIN klship.[dbo].[PCH1] T1 ON T0.[DocEntry] = T1.[DocEntry]
    INNER JOIN klship.[dbo].[OJDT] T5 ON T0.[TransID] = T5.[TransID]
    WHERE
    (T0.[UpdateDate] >= '[%2]' AND
    T0.[UpdateDate]  <= '[%3]' AND
    T0.[U_SupInv] IS NULL)
    OR
    (T0.[UpdateDate] >= '[%4]' AND
    T0.[UpdateDate]  <= '[%5]' AND
    T0.[U_SupInv] IS NOT NULL)
    FOR BROWSE

    Dear István Korös,
    Thanks a lot for your answer.
    I will test your suggestion tomorrow, as it's night and I am returning home now.
    However, I do not think it will suit my requirements for the foll reasons:
    - I worked hard to get rid of the need to enter anything in the @Scan2 field.
    - This UDF was created solely as a text of instruction for my staff.
       Unfortunately I had to fill in something to make the Query work.
    - The problem is that if the user forgets to click the drop-down arrow and leaves @Scan2
       blank, the query does not work.
    - With the help of another expert, I succeeded in ignoring @Scan2 altogether.
    - I posted only a simplified version of my Query on the forum, without the codes relating to eliminating the
      need to enter something in @Scan2, so you may not be aware of my requirement.
    - I hope you understand my reluctance. But I will try your suggestion nevertheless.
    My Suggestion
    I think using PCH1.VISORDER may be the solution.
    If we select only those rows where visorder = 0, then
       - there will be no duplication
       - I need not use SELECT DISTINCT
       - All my LINKS to pdf files will be live because I need not use CAST
       - I may retain that part of my Query which permits ignoring @Scan2 altogether.
    - A Dream!-
    The problem is that I don't know how and where  to place that VISORDER.
    If you think I may be right, could you help me along that line?
    Best Regards
    Leon Lai

  • Problems with "Select Distinct" Statement

    Hi... I've a little problem with my SQL Statement...
    I've a Table in a DataBase with Solds of the Month... the fields are: vta_fecha, vta_prod, vta_total, vta_mesa.
    I've to Select only the distincts fields of vta_prod... selected by vta_fecha and vta_mesa...
    My code is like this:         try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                conec = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/POOL/Data/BaseDat.MDB");
                state = conec.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);try{
                rec = state.executeQuery("Select DISTINCT vta_prod, vta_fecha, vta_mesa from Ventas where vta_fecha = #" + Fecha_q + "# And vta_mesa = 0");           
                rec.first();
                int x = 0;
                while (rec.isAfterLast()==false){
                    x++;
                    rec.next();
                rec.first();
                if (x > 0){
                    Productos = new String[x];
                    Total_Vta = new int[x];
                    Cant_Prod = new int[x];
                    x = 0;
                    while (rec.isAfterLast() == false){
                        Productos[x] = rec.getString("vta_prod");
                        rec.next();
                        x++;
                else{
                    Productos = new String[0];
                    Total_Vta = new int[0];
                    Cant_Prod = new int[0];
            }catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());}Now, in the Table I have only 3 diferents vta_prod, but this Statement returns 9 Rows... and I don't know why...
    Please help me...
    Regards...

    I don�t have a complete picture because I don�t know what values you are passing in the select and I don�t know your column types but this is what I think is happening from what you have shared.
    You may have misunderstood what the DISTINCT keyword does.
    The DISTINCT keyword applies to the full set of columns in the select (not just the first column). So in your case it would be equivalent to:
    SELECT vta_prod, vta_fecha, vta_mesa
    FROM Ventas
    WHERE ...
    GROUP BY by vta_prod, vta_fecha, vta_mesa
    So, it doesn't matter that you only have 3 distinct vta_prod values if you have multiple values being returned in the other columns. The vta_mesa column can only a return a single value as �0�. That leaves the vta_fecha column which is probably a date/time column and is probably the column that is returning the three other distinct values (one date with three distinct times).
    (3 vta_prod) x (3 vta_fecha) x (1 vta_mesa) or 3x3x1 = 9 rows
    So find a way to strip the time from vta_fecha in your select statement and your SQL should return the results you expect. I�m not an Access expect but I think I remember you can use something like the �Convert� or �DatePart� functions to make that happen (check your documentation to be sure)..
    A couple of asides;
    1) You should use a PreparedStatement and rarely if ever use Statement.
    2) You should start Java variable names with lower case.

  • SELECT DISTINCT jcbc:odbc problem

    I'm writing an application which uses the jdbc:odbc bridge.
    One of the sql statements is a SELECT DISTINCT.
    The exact sql is simply:
    "SELECT DISTINCT collection FROM collections"If the sql I use is put into Access, it returns the two unique records, as desired. However, when I use it in Java, I get 10 records returned (i.e. the number of records in the table) - the first two are the correct two unique records, whilst the remaining 8 are simply null.
    Any ideas why?

    It's a matter of interpretation, how null values are handled for DISTINCT and also for grouping by the GROUP BY clause.
    A DBMS must choose one of these alternatives:
    1) You can ignore null. This is, what your Access seems to do.
    2) You can handle null as one value, so DISTINCT returns 1 row that's standing for all null values.
    3) You can handle each null as one value, so DISTINCT returns all null value rows. This is, what you get with Java. (I'm not sure if it's JDBC generally or your specific driver.)
    The background: "null" means: "unknown". And if two values are both "unknown", you can't simply say: they are equal.
    Btw. you encounter a similiar interpretation matter for null values by sorting: is null the biggest or the smallest value?
    If you are not content with your DBMS' interpretation of null values or - what I would recommend - want to be independant from the interpretation at all, you should deal with the null values explicitely.
    So in your example - obviously you don't want the null values at all:
    For Access and Java use:"SELECT DISTINCT collection FROM collections WHERE NOT collection IS NULL"

  • "connect by" problem with "select distinct"

    When I run the following SQL (using "Scott" DB):
    select *
    from emp
    where deptno = 30 or mgr is null
    start with mgr is null
    connect by prior empno = mgr
    order siblings by ename
    I get the results one would expect. The President is first and all those reporting to him/her are listed in correct sequence.
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    7839,KING,PRESIDENT,,11/17/1981,5000,10
    7698,BLAKE,MANAGER,7839,5/1/1981,2850,30
    7499,ALLEN,SALESMAN,7698,2/20/1981,1600,300,30
    7900,JAMES,CLERK,7698,12/3/1981,950,30
    7654,MARTIN,SALESMAN,7698,9/28/1981,1250,1400,30
    7844,TURNER,SALESMAN,7698,9/8/1981,1500,0,30
    7521,WARD,SALESMAN,7698,2/22/1981,1250,500,30
    However, when I run the same query but make it "select distinct" I get the following:
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    7499,ALLEN,SALESMAN,7698,2/20/1981,1600,300,30
    7698,BLAKE,MANAGER,7839,5/1/1981,2850,,30
    7900,JAMES,CLERK,7698,12/3/1981,950,,30
    7839,KING,PRESIDENT,,11/17/1981,5000,,10
    7654,MARTIN,SALESMAN,7698,9/28/1981,1250,1400,30
    7844,TURNER,SALESMAN,7698,9/8/1981,1500,0,30
    7521,WARD,SALESMAN,7698,2/22/1981,1250,500,30
    Why would adding "distinct" to the select cause the result to be sorted STRICTLY by ename (per "order siblings by...")?
    Finally, if I "select distinct" but don't specify any "order" I get this, in NO APPARENT order:
    EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO
    7499,ALLEN,SALESMAN,7698,2/20/1981,1600,300,30
    7521,WARD,SALESMAN,7698,2/22/1981,1250,500,30
    7654,MARTIN,SALESMAN,7698,9/28/1981,1250,1400,30
    7698,BLAKE,MANAGER,7839,5/1/1981,2850,,30
    7839,KING,PRESIDENT,,11/17/1981,5000,,10
    7844,TURNER,SALESMAN,7698,9/8/1981,1500,0,30
    7900,JAMES,CLERK,7698,12/3/1981,950,,30
    Thanks in advance for any insight offered!
    -Gene

    you have to specify what is going to be the distict field.No you don't. DISTINCT keyword applies to the whole SELECT list. See your own link.
    In any case this does not appear to have anything to do with what you SELECT, rather that the SORT UNIQUE caused by the DISTINCT keyword appears to prevent the ORDER SIBLINGS BY clause from working correctly.
    Not really sure why you need DISTINCT in this example, no doubt this is being applied elsewhere. Given that you have duplicates in the rowset and that hierarchical query now supports views, perhaps it would be more efficient to apply DISTINCT keyword first, something like...
    SELECT e.*
    FROM (SELECT DISTINCT e.*
    FROM emp e
    WHERE e.deptno = 30
    OR e.mgr IS NULL) e
    START WITH e.mgr IS NULL
    CONNECT BY PRIOR e.empno = e.mgr
    ORDER SIBLINGS BY e.ename;
    Alternatively you could skip ORDER SIBLINGS BY clause and use SYS_CONNECT_BY_PATH function to get your order, something like...
    SELECT e.*
    FROM (SELECT DISTINCT e.*,
    SYS_CONNECT_BY_PATH () path
    FROM emp e
    WHERE e.depno = 30
    OR e.mgr IS NULL
    START WITH e.mgr IS NULL
    CONNECT BY PRIOR e.empno = e.mgr) e
    ORDER BY e.path
    Padders

  • 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 AM

    Hi,
    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
    ;

  • 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 regards

    Hi 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 bug ?

    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.

  • SELECT DISTINCT in MySQL gives error...

    Anyone help with this one - I'm sure it's easy.
    I have a working bean for a jsp where the statement sent to the QUERY is >> private String "SELECT * FROM mytablename ORDER BY afieldname <<. It works fine and there's no overt problems. But I dont want to return all the >> hasNext in the resultSet rs << To see the working example of why, log in at www.klaatu2u.com and go to the "ballets" menu item.
    I'm trying to modify the query string to
    private String "SELECT DISTINCT afieldname FROM mytablename ORDER BY afieldname " << and it's giving me a column index out of range error 3 > 1 error. As far as I can tell this comes from the resultset class in the see here below//error i keep getting...from mysql/jdbc2/
    // if (columnIndex < 1 || columnIndex > Fields.length) {
    // throw new java.sql.SQLException("Column Index out of range ( " + columnIndex + " > " + Fields.length + ").", "S1002");
    At any rate it is erroring on my mod'd query string. No clue as to why it wont see the column index properly. I have tried "SELECT DISTINCT afieldname FROM tablename WHERE afieldname = '*' " and it doesnt give the error, just no resultset.
    I'm using NETBEANS for my compiler :-/ , and mysql connector-j. I'm doing a lot of other fun stuff with it (stringtokenizing data for SPEED!) and all works well - just the DISTINCT myfieldname is no-go.
    No I'm not to smart - but could sure use help anyway. Thanx much for anyone who responds...

    thanks for the incredible ZERO replies and suggestions - anyhow it's fixed .

  • SELECT DISTINCT does not work. Why?

    Dear All,
    I wrote the Query below in SAP B1 8.8 and it works fine.
    But, for some strange reason, certain records are duplicated.
    Could anybody explain why?
    I tried to eliminate the duplicates by changing the 1st line of the Query from SELECT to SELECT DISTINCT
    Error Message:
    The ntext data type cannot be selected as DISTINCT because it is not comparable.
    Could you help amend the Query?
    Thanks
    Leon Lai
    SELECT
    T0.[UpdateDate] AS 'Update Dt',
    T0.[TaxDate] AS 'Doc Dt',
    CASE T5.[TransType]
         WHEN '18' THEN 'PU ' + CONVERT(VARCHAR(6), T0.[DocNum])
         WHEN '19' THEN 'PC ' + CONVERT(VARCHAR(6), T0.[DocNum])
    END 'SAP Ref.',
    T1.[ImportLog]     AS 'Ship #',
    T0.[CardCode] + '' AS 'Supplier #',
    T0.[CardName]      AS 'Supplier Name',
    T0.[DocTotal]      AS 'Rs',
    T1.[BlockNum]      AS 'Reqn #',
    T0.[DocNum]        AS 'Doc No',
    T0.[U_SupInv]      AS 'Link'
    FROM klship.[dbo].[OPCH] T0
    INNER JOIN klship.[dbo].[PCH1] T1 ON T0.[DocEntry] = T1.[DocEntry]
    INNER JOIN klship.[dbo].[OJDT] T5 ON T0.[TransID] = T5.[TransID]
    WHERE
    (T0.[UpdateDate] >= '[%2]' AND
    T0.[UpdateDate]  <= '[%3]' AND
    T0.[U_SupInv] IS NULL)
    OR
    (T0.[UpdateDate] >= '[%4]' AND
    T0.[UpdateDate]  <= '[%5]' AND
    T0.[U_SupInv] IS NOT NULL)
    FOR BROWSE
    Note: -  U_SupInv is a UDF used to attach a scanned pdf file to the Supplier's Invoice.

    Dear István Korös,
    Thanks a lot for your answer.
    Your suggestion works!
    I am closing this thread.
    However, I have never met the problem of duplicate records before
    with such straightforward Queries.
    If you could explain to me why such duplicates arose, it would be very
    satisfying.
    Best Regards
    Leon Lai

  • 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

  • SELECT DISTINCT OBJECT and ntext

    Hello,
    How can I write an ejb query that selects distinct ejbs, given that the underlying data table has NTEXT data in it?
    The old ejb query
    <ejb-ql><![CDATA[
    SELECT DISTINCT OBJECT(a) FROM Article AS a
    ]]></ejb-ql>
    used to work fine in weblogic 7, but it gives problems in wl8, where it transforms the ejbQl into a actual sql SELECT DISTINT FROM article
    command to the database (sql server) which in turn throws an sql exception about trying to select distinct when the table has an ntext column...
    Any help appreciated!

    One solution is the following:
    - use ejbSelect
    - and specify the exact columns you want distinct upon
    The reason the code was working in 7 was that distinct was done in (weblogic) code rather than pass on the database. Now in 8 distinct is passed on to the database (which is the correct behavior).
    Hello,
    How can I write an ejb query that selects distinct
    t ejbs, given that the underlying data table has
    NTEXT data in it?
    The old ejb query
    <ejb-ql>[CDATA[
    SELECT DISTINCT OBJECT(a) FROM Article AS a
    ]]</ejb-ql>
    used to work fine in weblogic 7, but it gives
    problems in wl8, where it transforms the ejbQl into a
    actual sql SELECT DISTINT FROM article
    command to the database (sql server) which in turn
    throws an sql exception about trying to select
    distinct when the table has an ntext column...
    Any help appreciated!

Maybe you are looking for

  • I can no longer search in the address bar, yahoo, or google. Help

    Not able to search in the address bar, yahoo search, google, and no google mail, or anything that I don't already have a link to in my most visited list or email i have received from them. I can't copy and paste because i'm writing you on my desktop.

  • Finf=d the token of Remote appl.

    Hi, Maybe a simple question. But I want to use a remote appl. This application uses SOAP and it needs the token. But where can I read the token for this application ? I use Teaming 2.0 Greetings, Rob

  • Can't open up application filter assignment in shared services

    Can't open up application filter assignment in shared services, and this applies to all applications in a 9.3 production environment. It only says "Refer to the Security Guide to configure security permissions for this application. " And this message

  • CANNOT CONNECT WITH APPLICATION HOSTED ON NETWORK

    Hi, I created a small application with Oracle 10gXE and hosted it on my PC which serves as the hub of our network in my office. However, I have not been able to access the application from other PCs on the network. What should I do? The application w

  • Can't upload photos to mobile me gallery

    The first one went through ok, now after several minutes I get a message that says it could not be uploaded, no reason or error code. I also can't seem to log in to mobile me, I just keep getting the same page wanting me to set it up, which is alread