Results 1 to 4 of 4

Thread: SQL Query Urgent

  1. #1
    Join Date
    Oct 2007
    Posts
    3

    SQL Query Urgent

    Hai Every one
    I need one SQL Query
    Consider 2 tables A,B.
    They have one column called status
    User Enters one GroupId in From and click on search button
    Tht group id must be there in any one of the table.
    If groupID in Table A then it has to retrive the status from Table A.If the GroupID in Table B then it has to retrive status from Table B.
    This is my requirement.
    Can any one help me to find the query

  2. #2
    Join Date
    Oct 2007
    Posts
    2

    I think this will do the trick

    I have tested this one, and below is my solution. As far as I understand it, group_id is a unique value in both tables, therefore giving one status per group_id. This works for my oracle database.

    regards,

    John

    select nvl(
    (select status from a where group_id = <group_id>),
    (select status from b where group_id = <group_id>)
    ) from dual

  3. #3
    Join Date
    Oct 2007
    Posts
    1
    Hope this will give your result..

    select a.col1,a.col2,(case when a.group_id = <groupid> then
    a.status
    when b.group_id = <groupid> then
    b.status
    else
    null
    end) status
    from a,b
    where a.col1=b.col1;

    regards

    Hari

  4. #4
    Join Date
    Oct 2007
    Posts
    1

    Thumbs up Solution

    You may this the following solution.

    select status from
    (
    select status,group_id from a
    union
    select status,group_id from b
    )
    where group_id = <groupid>;

    Regards
    Zame

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •