You must Sign In to post a response.
  • Category: SQL Server

    Query to get data from two tables

    I need to get records from two tables which don't have any criteria as matching i.e pkey and fkey matching etc.The database used is ms access.Below is the query generated by query wizard but is returns records when number of rows in both the table are equal.

    SELECT Table1.*, Table2.*FROM Table1, Table2;

    i want to get all the available records from table1 and table2.

    Any suggestions
    Thanks in advance
  • #732251
    Hi Smile,

    Try this below qry.....


    SELECT * FROM
    (SELECT ROW_NUMBER() OVER(ORDER BY ANY_COLUMN_NAME) AS ROW,* FROM TABLE1)A
    FULL OUTER JOIN (SELECT ROW_NUMBER() OVER(ORDER BY ANY_COLUMN_NAME) AS ROW,* FROM TABLE2)B ON
    A.ROW=B.ROW




    Hope this helps you if it is means mark this answer!!

    Regards,
    Sri

  • #732260
    Hi smile,

    There is no relation between those two tables what's the need to use both tables and combine result. Ok if you want to fetch both table combine result then you just simply use in select statement without wrote any conditions.

    EX:


    select t1.col,t2.col
    from table1 t1, table2 t2


    Hope this will help you to resolve the issue..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #732264
    There is no relation between those two tables what's the need to use both tables and combine result.

    select t1.col,t2.col
    from table1 t1, table2 t2

    Any doubts please ask me

  • #732275
    There are verious way to get data from two table . You can try to use this statement as guide line for your query
    SELECT lname, fname, open_weekends
    FROM vehicles, locations WHERE Vehicles.location = vehicles1.location
    AND vehicles.location = locations1.location
    AND locations.open_weekends = 'Yes'

  • #732280
    HI,

    Use Union keyword in sql to get all the rows of both the tables.


    SELECT column_name(s) FROM table1
    UNION
    SELECT column_name(s) FROM table2;


    Hope it will be useful.

    Regards,
    T.N. THEAAVARAAJ
    Senior Software Engineer,
    Microsoft Certified Technology Specialist.
    Email:devabe2005@gmail.com

  • #732333
    Hai Smile,
    If you are using the MS-Access as your database and want to get the results based on two tables, then you can go to the query object at the left side and create the query for both the tables to get the data.
    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com

  • #735445
    select a1.columname1,a1.columnname2,a2.columnname1,
    a2.columnname2 from tablename1 a1,tablename2 a2



    hope this i will help.....


  • Sign In to post your comments