Select Data From Two Tables And show distinct  records and second  table records come first then  first table record and having relationship.

Posted on 2009-04-20
Last Modified: 2013-12-07
Suppose i have table name tblfavuser(Contains data of favorite user)    and tbluser(contains the user data). I  want to show distinct record from both table and tblfavuser comes first then tbluser.
Question by:Gurbirs
    LVL 4

    Expert Comment


    You can use Union

    Select, from fav_user
    Select, from user

    LVL 31

    Expert Comment

    Can you post some sample data and the expected results?
    LVL 9

    Accepted Solution


    col ordertype noprint
    SELECT 1 ordertype, tblfavuser.*
      FROM tblfavuser
      WHERE not exists (select 1
                                        from tbluser
                                       where =
    SELECT 2, tbluser.*
       FROM tbluser
     WHERE not exists (select 1
                                        from tblfavuser
                                       where =
    order by 1

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
    Introduction A previously published article on Experts Exchange ("Joins in Oracle", makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
    This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
    This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now