Checking multiple columns using "IN"

I have a query
select 1 from tableA
where
cond1 = val1 and
exists
( col1, col2, col3, col4 ) IN
( select
     cola, colb, colc, cold
from
     table B
where
     cond1 = val1
Will this condition Checking for multiple columns in the IN work ?
I actually mispelled a column name ( say colb ) in the sub query but it did not give a error, but executed fine by matching part of the columns alone?

The execution plans look strangely similar.
SQL> CREATE TABLE t1 (c1 INT NOT NULL, c2 INT NOT NULL, c3 INT NOT NULL);
Table created.
SQL> INSERT INTO t1 (c1,c2,c3)
  2  SELECT dbms_random.value(0,9)
  3       , dbms_random.value(0,99)
  4       , dbms_random.value(0,999)
  5  FROM   dual CONNECT BY LEVEL <= 10000;
10000 rows created.
SQL> CREATE TABLE t2 AS SELECT * FROM t1 SAMPLE BLOCK(10);
Table created.
SQL> BEGIN
  2      DBMS_STATS.GATHER_TABLE_STATS(user,'T1');
  3      DBMS_STATS.GATHER_TABLE_STATS(user,'T2');
  4  END;
  5  /
PL/SQL procedure successfully completed.
SQL> SELECT * FROM t1 WHERE (c1,c2,c3) IN
  2         ( SELECT c1,c2,c3 FROM t2 )
  3 
SQL> @xplan
Plan hash value: 1275841967
| Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT     |      |     1 |    18 |    12   (9)| 00:00:01 |
|*  1 |  HASH JOIN RIGHT SEMI|      |     1 |    18 |    12   (9)| 00:00:01 |
|   2 |   TABLE ACCESS FULL  | T2   |   209 |  1881 |     3   (0)| 00:00:01 |
|   3 |   TABLE ACCESS FULL  | T1   | 10000 | 90000 |     8   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - access("C1"="C1" AND "C2"="C2" AND "C3"="C3")
SQL> SELECT * FROM t1 WHERE EXISTS
  2         ( SELECT NULL FROM t2
  3           WHERE  c1 = t1.c1                   
  4           AND    c2 = t1.c2
  5           AND    c3 = t1.c3 )
  6 
SQL> @xplan
Plan hash value: 1275841967
| Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT     |      |     1 |    18 |    12   (9)| 00:00:01 |
|*  1 |  HASH JOIN RIGHT SEMI|      |     1 |    18 |    12   (9)| 00:00:01 |
|   2 |   TABLE ACCESS FULL  | T2   |   209 |  1881 |     3   (0)| 00:00:01 |
|   3 |   TABLE ACCESS FULL  | T1   | 10000 | 90000 |     8   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   1 - access("C1"="T1"."C1" AND "C2"="T1"."C2" AND "C3"="T1"."C3")
SQL>

Similar Messages

  • How to retrieve multiple columns using "returning" in the Insert query.

    hi,
    wanted to know how to retrieve multiple columns using "returning" in the Insert Query.
    For retrieving one column we write the query as follows:
    Insert into TABLE values(1,2,3,4) returning COLUMN1 into PARAMETER
    But can we retrive multiple columns in the same query?
    am using oracle 10g and coding in .NET

    Hi,
    You can definetely get multiple values from a single query using the 'returning' clause.
    Eg : insert into emp (empno, ename, job, deptno) values (7324,'ADAM','MARKETING',30) returning ename, deptno into var1, var2; PN : var1 & var2 to be declared as varchar2 & number respectively.
    More insight into the 'RETURNING' clause in this link.
    http://www.samoratech.com/PLSQL/swArtPLSQLReturn.htm
    Regards,
    Bhanu.

  • Split flat file column data into multiple columns using ssis

    Hi All, I need one help in SSIS.
    I have a source file with column1, I want to split the column1 data into
    multiple columns when there is a semicolon(';') and there is no specific
    length between each semicolon,let say..
    Column1:
    John;Sam;Greg;David
    And at destination we have 4 columns let say D1,D2,D3,D4
    I want to map
    John -> D1
    Sam->D2
    Greg->D3
    David->D4
    Please I need it ASAP
    Thanks in Advance,
    RH
    sql

    Imports System
    Imports System.Data
    Imports System.Math
    Imports Microsoft.SqlServer.Dts.Pipeline.Wrapper
    Imports Microsoft.SqlServer.Dts.Runtime.Wrapper
    Imports System.IO
    Public Class ScriptMain
    Inherits UserComponent
    Private textReader As StreamReader
    Private exportedAddressFile As String
    Public Overrides Sub AcquireConnections(ByVal Transaction As Object)
    Dim connMgr As IDTSConnectionManager90 = _
    Me.Connections.Connection
    exportedAddressFile = _
    CType(connMgr.AcquireConnection(Nothing), String)
    End Sub
    Public Overrides Sub PreExecute()
    MyBase.PreExecute()
    textReader = New StreamReader(exportedAddressFile)
    End Sub
    Public Overrides Sub CreateNewOutputRows()
    Dim nextLine As String
    Dim columns As String()
    Dim cols As String()
    Dim delimiters As Char()
    delimiters = ",".ToCharArray
    nextLine = textReader.ReadLine
    Do While nextLine IsNot Nothing
    columns = nextLine.Split(delimiters)
    With Output0Buffer
    cols = columns(1).Split(";".ToCharArray)
    .AddRow()
    .ID = Convert.ToInt32(columns(0))
    If cols.GetUpperBound(0) >= 0 Then
    .Col1 = cols(0)
    End If
    If cols.GetUpperBound(0) >= 1 Then
    .Col2 = cols(1)
    End If
    If cols.GetUpperBound(0) >= 2 Then
    .Col3 = cols(2)
    End If
    If cols.GetUpperBound(0) >= 3 Then
    .Col4 = cols(3)
    End If
    End With
    nextLine = textReader.ReadLine
    Loop
    End Sub
    Public Overrides Sub PostExecute()
    MyBase.PostExecute()
    textReader.Close()
    End Sub
    End Class
    Put this code in ur script component. Before that add 5 columns to the script component output and name them as ID, col1, co2..,col4. ID is of data type int. Create a flat file destination and name it as connection and point it to the flat file as the source.
    Im not sure whats the delimiter in ur flat file between the 2 columns. I have use a comma change it accordingly.
    This is the output I get:
    ID Col1
    Col2 Col3
    Col4
    1 john
    Greg David
    Sam
    2 tom
    tony NULL
    NULL
    3 harry
    NULL NULL
    NULL

  • How to transpose rows into multiple columns using pivot table

    I have 1 row containing 12 columns with value "JAN", "FEB", "MAR", "J-1","F-1","M-1","J-2","F-2","M-2","J-3","F-3","M-3"
    I want to display as
    JAN J-1 F-1 M-1
    FEB J-2 F-2 M-2
    MAR J-3 F-3 M-3
    How do I achieve the above?

    Today you have only 3 months JAN, FEB, MAR. Is it always the same number of columns. What if there are more months added to this row?
    Is your data really coming from relational source or some sort of text file?
    There is a better way to do this in narrative view using HTML if your requirement is just to show them in multiple rows and do some calculations.
    Go to Narrative View;
    In prefix, use <html> <table>
    In 'Narrative' text box add something like this
    <tr> <td> @1 </td> <td> @4 </td> <td> @7 </td> </tr>
    <tr> <td> @2 </td> <td> @5 </td> <td> @8 </td> </tr>
    <tr> <td> @3 </td> <td> @6 </td> <td> @9 </td> </tr>
    In Suffix, use </table> </html>
    You can also add simple calculations like sum etc at the very bottom of these rows as grand totals.
    kris

  • Multiple Columns using a single CASE

    Hi,
    I have a SQL statement:
    SELECT
    CASE WHEN
    c.code=b.code
    AND c.from_id=b.to_id
    THEN
    COLA
    ELSE
    COLB
    END "Exampl1"
    CASE WHEN
    c.code=b.code
    AND c.from_id=b.to_id
    THEN
    DATEA
    ELSE
    DATEB
    END "Exampl2"
    FROM
    table_a a,table_b b,
    SELECT *
    FROM
    table_c
    WHERE TYPE='REC') c
    WHERE
    a.code=b.code
    I want to use the CASE statement one time not twice to fetch the required for Example1 and Example 2
    Can it be possibleb?
    Kindly any help will be benefitial to me

    >
    I want to use the CASE statement one time not twice to fetch the required for Example1 and Example 2
    Can it be possibleb?
    >
    No - A CASE result is a singel statement and in a SELECT must be a single value.
    So 'COLA' is ok but 'COLA, DATEA' will not work.
    Just use the CASE once for each column like you are doing.

  • How to add multiple columns using select statement

    Hi friends
    i have two TABLES
    one table Contain only unique Agent code(23,45,56,88)
    second table contain same Agent Code,orderdate & sum(amount)
    now i want to add columns in table 1 according to date and update the amount in that column
    for example if i select start date 1st july 2014 and end date is 15 july 2014
    then i want result 
    select agentcode,amount as 01july2014,amount as 02nd july2014 up to 15th july
    Please HELP.....

    >> I have two TABLES <<
    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. You failed on this too!  Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. Ignorance is fine, but why do you have bad manners? The rules are posted at the front of the forum! 
    >> one [nameless, unknown] table Contain only unique Agent code(23, 45, 56, 88) <<
    You do not know the difference between a code and an identifier!
    CREATE TABLE Agents
    (agent_id INTEGER NOT NULL PRIMARY KEY); 
    >> second table contain same Agent Code, order_date & SUM(order_amount) <<
    Wrong again! The SUM() is an aggregate function and cannot be in a column. Tables have keys
    CREATE TABLE Orders
    (agent_id INTEGER NOT NULL
       REFERENCES Agents(agent_id),
     order_date DATE NOT NULL,
     order_amt DECIMAL (8,2) NOT NULL,
     PRIMARY KEY (agent_id, order_date));
    >> now I want to add columns in table 1 according to date and update the amount in that column <<
    NO! The running total is a computed column. We do not store them.
    >> for example if I select start date 1st July 2014 [sic: 2014-07 -01] and end date is 15 July 2014 [sic: 2014-07-15] <<
    If you have ever read a book on SQL, you would know the correct display format for dates! It is the only one in the ANSI/ISO Standards. 
    SELECT agent_id, order_date,
           SUM(order_amt) 
           OVER (PARTITION BY agent_id
                    ORDER BY order_date
                  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
           AS order_amt_runtot
      FROM Orders
     WHERE order_date BETWEEN '2014-07-01' AND '2014-07-15'; 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Need to update multiple columns using another table

    I have 2 tables. and i need to update rows of 1 table using another table
    Table1
    Serial_no.     payment_date     Payment_amt
    101     22/11/2010     150
    101     18/03/2011      355
    102     15/04/2011      488
    103     20/05/2011      178
    102     14/06/2011      269
    101     28/06/2011      505
    Table2
    Serial_no     Charge_amt      Last_paymt_dt     Last_paymt_amt
    101     255
    102     648
    103     475
    I want to update Last_paymt_dt and Last_paymt_amt of table2 using Table1, I have written following update statement but it gives error that single row subquery return multiple row.
    Update Table2
    set (Last_paymt_dt,Last_paymt_amt) = (select max(payment_date, payment_amt) from table1
    where table1.Serial_no = table2.Serial_no group by payment_amt)
    kindly suggest how should i update.

    SQL> select * from table1
      2  /
    SERIAL_NO PAYMENT_DA PAYMENT_AMT
           101 22/11/2010         150
           101 18/03/2011         355
           102 15/04/2011         488
           103 20/05/2011         178
           102 14/06/2011         269
           101 28/06/2011         505
    6 rows selected.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255
           102        648
           103        475
    SQL> update  table2
      2     set  (last_paymt_dt,last_paymt_amt) = (
      3                                            select  max(payment_date),
      4                                                    max(payment_amt) keep(dense_rank last order by payment_date)
      5                                              from  table1
      6                                              where table1.serial_no = table2.serial_no
      7                                           )
      8  /
    3 rows updated.
    SQL> select * from table2
      2  /
    SERIAL_NO CHARGE_AMT LAST_PAYMT LAST_PAYMT_AMT
           101        255 28/06/2011            505
           102        648 14/06/2011            269
           103        475 20/05/2011            178
    SQL> SY.

  • Split single column into multiple column using sql /plsql

    create table test (name varchar2(255);
    insert into test values('DH  RED 20 12/10 10 2 ');
    insert into test values('PM  STUD 20 15/10 20 29.55' );
    insert into test values('LS  MENTHOl FILTER ASC 18/70 60 240.66');
    insert into test values('WINSTON WHITE CLASSIC 13    18/70 60 240.66');
    My Output should be like as below in other table :
    create table test_result (brand varchar2(255),packet   varchar2(50),amount varchar2(25),total varchar2(25));
    BRAND                                   PACKET       AMOUNT           TOTAL
    DH  RED 20                            12/10            10              2
    PM  STUD 20                           15/10            20              29.55
    LS  MENTHOl FILTER ASC               18/70            60              240.66
    WINSTON WHITE CLASSIC 13             18/70            60              240.66can you please help me to solve this issue
    thanks in advance
    Edited by: A on Apr 21, 2012 11:33 PM
    Edited by: A on Apr 21, 2012 11:34 PM
    Edited by: A on Apr 21, 2012 11:34 PM

    h4. # Database should be 10g. If version is below 10g query need to be modified as per string format.
    h4. # Split string into two parts by '/'. First part contain brand + packet(1), Second part contain packet(2) + amount + total
    h4. # Your brand name can be of any length.
    String Format* : <Brand Name><space><packet(1)>/<packet(2)><space><amount><space><total>
    SELECT name,
           REGEXP_SUBSTR(first_part,'.+[[:space:]]',1,1) brand,
           REGEXP_SUBSTR(first_part,'[^[:space:]]+/',1,1) || REGEXP_SUBSTR(second_part,'[^[:space:]]+[[:space:]]',1,1) packet,
           REGEXP_SUBSTR(second_part,'[^[:space:]]+[[:space:]]',1,2) amount,
           REGEXP_SUBSTR(second_part,'[^[:space:]]+$',1) total
    FROM
      (SELECT trim(name) name,
              trim(substr(name,1, instr(name,'/'))) first_part,
              trim(substr(name,instr(name,'/')+1)) second_part
       FROM test )
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Content Query display multiple columns

    Hello,
    I am using a content query web part (in sharepoint 2013) to display a list from another site. The problem is that I don't see enough info from that list because I can display maximum 2 columns.
    Is it possible to display more columns from this list with the Content query web part? I would like to display all the columns from this list. Do i need to make a display template or something? 
    Thanks. 

    You have to customize the CQWP.
    Please check the below link
    http://pholpar.wordpress.com/2010/01/21/displaying-results-in-multiple-columns-using-the-content-query-web-part/
    Other option is you ca use Dataview webpart to show the list details from one site to other site
    http://www.learningsharepoint.com/2012/08/12/sharepoint-2013-add-dataview-webpart-with-sharepoint-designer-2013/
    http://sharepointgeorge.com/2009/display-sharepoint-list-site-data-view-web-part/
    MCTS,MCPD Sharepoint 2010. My Blog-
    http://www.sharepoint-journey.com
    If a post answers your question, please click "Mark As Answer" on that post and "Vote as Helpful

  • Full text query across multiple columns

    In the SQL Server, when you do the full text query, you can specify multiple columns, e.g.
    FREETEXT ( { column_name | [b](column_list) | * } , 'freetext_string' [ , LANGUAGE language_term ] )
    CONTAINS ( { column_name | [b](column_list) | * } , '< contains_search_condition>' [ , LANGUAGE language_term ])
    Where,
    column_list Indicates that several columns, separated by a comma, can be specified...
    * Specifies that all columns in the table registered for full-text searching should be used to search for the given contains search condition. The columns in the CONTAINS clause must come from a single table...
    That makes full text query cross multiple columns very convenient. Are there any mechnisms in Oracle to do the same thing?
    Thanks in advance.

    Thanks for your reply.
    I knew that you could build full text index for the multiple columns using Oracle Text. But that does not solve my problem, which is how to build the query to search multiple columns at once. Say, I have columns firstname, lastname, address, and email in the table customers. I want to get the results that ANY column contains 'bob'. In SQL Server, I can do
    select * from customers where contains(*, 'bob')
    that is. But for Oracle, I have to do
    select * from customers where contains('firstname', 'bob') or contains('lastname', 'bob') or contains('address', 'bob') or contains('email', 'bob')
    Can you imagine if I have many columns in many tables and I have to do the query against all columns in all tables? I have to dynamically get all the columns and then build the query string.
    So, any better solutions?

  • Linq selecting multiple columns when using anonymous types using Sum multiple columns

    I have a list with multiple columns where I need to sum a list of columns for each row into a new column (not 100% sure if there is another way to sum other than I have done it). Problem I'm having is being able to select more than just column I'm creating
    used from summing the other column and the Key. Below will produce a row with the CustomerId and the total of all the months.
    CustomerId
    Total
    12345
    2500.00
    12346
    3000.00
    But let's say I have a row called Name in "history"--how can display it in the query results as below.  I'm unable to reference anything but the key.
    CustomerId
    Total
    Name
    12345
    2500.00
    John Smith
    12346
    3000.00
    May Allen
    var list = history
    .GroupBy(g => g.CustomerId)
    .Select(sg =>
    new
    Key = lg.Key,
    SumTotal = sg.Sum(x => x.month_01)
    + sg.Sum(x => x.month_02)
    + sg.Sum(x => x.month_03)
    + sg.Sum(x => x.month_04)
    + sg.Sum(x => x.month_05)
    + sg.Sum(x => x.month_06)
    + sg.Sum(x => x.month_07)
    + sg.Sum(x => x.month_08)
    + sg.Sum(x => x.month_09)
    + sg.Sum(x => x.month_10)
    + sg.Sum(x => x.month_11)
    + sg.Sum(x => x.month_12)

    Hi
    ajl7519,
    I have tested on my side,  please check my code. 
    InitializeComponent();
    AuctionItems = new List<AuctionItem>() {
    new AuctionItem() { Category = "Car", CurrentPrice = "100", Description = "100", SpecialFeatures = "100", StartDate = 1, StartPrice = 1 },
    new AuctionItem() { Category = "Car", CurrentPrice = "100", Description = "100", SpecialFeatures = "100", StartDate = 2, StartPrice = 2 },
    new AuctionItem() { Category = "Car", CurrentPrice = "100", Description = "100", SpecialFeatures = "100", StartDate = 3, StartPrice = 3 }
    var resu = AuctionItems.GroupBy(a => new { a.Category, a.Description }).Select(sg => new { ID = sg.Key.Category, Total = sg.Sum(oc => oc.StartPrice + oc.StartDate), Name = sg.Key.Description });
     You also can change your code to
    • SumTotal = sg.Sum(x => x.month_01+x.month_02+ ......)
    Have a nice day !
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • I need to host a Shared PDF on SharePoint. If it is on SharePoint can only one person comment at a time? I know documents have to be checked out when using SharePoint. I need multiple users to be able to comment in real time and see comments in real time.

    I need to host a Shared PDF on SharePoint 2010. If it is on SharePoint can only one person comment at a time? I know documents have to be checked out when using SharePoint. I need multiple users to be able to comment in real time and see comments in real time. Is this possible?

    try here:
    http://www.bbb.org
    File a complaint with them. Verizon will call you to fix the blunder.
    But remember it is always up to the customer to insure what they are getting and what it costs. Don't trust the word of a sales person who makes their living on getting that sale. Lies, deceit or false promises will be and have been used by sales people for thousands of years.
    Good Luck

  • How to use a USER_DATASTORE to index multiple columns in different tables

    I would appreciate if somebody can give an example or point to links with examples on how to use USER_DATASTORE on multiple columns in different tables. THe Oracle Text documentation only shows multiple columns in the same table.
    Thanks in advance.

    I am not sure why your getting the wrong results but you should seriously reconsider the approach your are taking. Using functions like this is very ineffecient and should be avoided at all cost.

  • How to make Multiple column listbox in CS4 using tree view

    Hi ,
    I am a beginer in Indesign Cs4 plug-in creation.In one scenario i want to create multiple column listbox,i tried with one cloumn using tree view and that is working fine.so suggest how to create multiple column listbox using tree view.
    thanks
    Arun

    InDesign does not have a native multi-column widget. You have three options:
    1) Use the treeview widget and align your widgets in the tree node to create the illusion of columns (stroke panel is an example - the Links panel in CS4 is a better example)
    2) Go the way of the CellPanel SDK example and tweek it to work like a listbox
    3) Create the User Interface in Flex

  • Writing several / multiple columns in a *.lvm file using write file option

    Hello All,
    I am doing several measurements and till now writing all the measurement in individual files thereby I am forced to use an external program to merge the files into one file of several columns.
    Is there a possibility to write a *.lvm file (or some other possibility say a *.txt file but no excel) with multiple columns where each column stands for a particular data?
    I am attaching a simple example where I have 4 different measurements (simulated using a regulator(I dont know how I can say this vi in english)??) which I am converting into array and trying to write them in a file of *.lvm extension. But the output is still a single column where every measurement is taking a different row which I dont want.
    Thanks in advance.
    Jan
    Attachments:
    Unbenannt 1.vi ‏97 KB

    Instead of using the Build Array, just wire your scalars to the Merge Signals function. This will create 4 separate signals that will be written in 4 separate columns. With the existing 1D array, you could also use the Write to Spreadsheet File instead of Write to Measurement File.

Maybe you are looking for