1

There is two tables there is nor relation between both tables,

structure: table_one

+---------+--------+-----------+
| name    | age    |insertTEMP |
+---------+--------+-----------+
| cat     | 12     |02-02-2014 |
| dog     | 13     |03-04-2014 |
+---------+--------+-----------+

structure: table_two

+---------+--------+---------------+
| book    | pages  | insertTEMP    |
+---------+--------+---------------+
| book1   | 34     | 05-02-2014    |
| book2   | 54     | 04-03-2014    |
+---------+--------+---------------+

now the idea is here i want to list records from both table so i keep bellow function to list them.

public function recentALL() {
   $sql = "select * from table_one, table_two ORDER BY insertTEMP";
    $q = $this -> conn -> prepare($sql);
    $q -> execute();
    return $row = $q -> fetchAll();
 }

and i fetch it in the view,

        $data2 = $functions->recentAll();
            foreach ($data2 as $data3){
                  echo $data3['name']  . $data3['book'] . '<br />';

           }

how i can make it to show like:

+---------+--------+
| cat     | NULL   |
| null    | book1  |
| null    | book2  |
| dog     | null   |
+---------+--------+

this based on the insertTEMP

Chisskarzz
  • 171
  • 2
  • 16
SAR
  • 1,765
  • 3
  • 18
  • 42

1 Answers1

0

Use the following query

Select * from (
    Select name  as Name, null as Book,insertTEMP  from table_one
    UNION ALL
    select null as Name, book as Book,insertTEMP  from table_two
) as tmp
Order by tmp.insertTEMP asc

Change the column names in your code as per query

Bilal Rao
  • 154
  • 8