Skip to content
Loading
  • +3
    You have several options to do that!
     
    The old fashion way is. 
     
    SELECT   alias1.col1,alias2.col1
    FROM       table1 as alias1, table2 as alias2
    WHERE    alias1.col1 = alias2.col2;
     
    The new way to join two tables is:
     
    SELECT   table1.col1,table2 col1
    FROM      table1
    INNER JOIN   table2 ON (table1.col1 = table2.col1)
    +3
  • +3
    Of course you can use UNION / UNION ALL but I think it's better to use INNER JOIN if you want to fetch data from totally different tables.

    An INNER JOIN is used to combine two tables into a new table. A UNION is used to combined rows into a new row. Duplicated rows are elimated when using UNION.
     
    Performance is actually almost the same. For better performance use indexes. 
    +3
  • +1
    U can use joins or else u can use Union /Union All
    +1
  • +1
    Two fetch records from Two tables There are two ways
    1.Union and Union All
    2.Joins
    1.Using Union and Union All needs the same table to have similar schematic structure 
    2.Using joins the both the table should have atleast one column to be having identical values from both the tables. 
    +1
  • 0
    Use Joins...... thats the best way
    0
  • Shahriar Nikkhah
    0
    try to find a relational field(s) in between both tables, so lets assume the related field is F1
    If you are 100% sure that this is the right key just use the right JOIN if not you must study and understand the data, to do that 
    1 - use a inner join on f1
    2- use a right join on f1
    3- user a left join on f1
     
    now check the number of orphan records and  parent without child, this approch will help you to validate the selected field (f1) in your joins
     good luck 
    0