1

It's my controller :

public function lihatpesanansemua() //ajax
{
    if(Request::ajax())
    {
        $hasil = DB::table('pesanan')->join('pemesan','pemesan.id', '=', 'pesanan.idpemesan')->join('komputer', 'komputer.id' ,'=', 'pesanan.idkomputer')
        ->select('pesanan.id', 'pemesan.nama', 'pesanan.tglpesan', 'pesanan.jampesan', 'pesanan.jamakhir', 'komputer.nama_komputer', 'komputer.lantai', 'komputer.Kelas')
        ->orderby('pesanan.id', 'asc')
        ->get();
        $hasil = json_encode($hasil);
        return $hasil;
    }
}

And that's is inner join. How to change to full outer join ? Thanks, sorry my bad english

Samuel Ricky
  • 69
  • 1
  • 2
  • 10
  • _Which_ join do you want to change? You currently appear to have _two_ inner joins in your query. – Tim Biegeleisen Jan 15 '17 at 14:13
  • That's going to be a lot of code. Are you sure you need full outer joins on _both_ queries? Maybe you can share some data with us and what result you are trying to get? – Tim Biegeleisen Jan 15 '17 at 14:17

2 Answers2

3

I don't know what exactly your query is trying to achieve, and where you need a full outer join, but I will begin this answer by saying that MySQL has no inbuilt support for full outer join. Based on this SO question, we can find a way an alternative way to write the following query:

SELECT * FROM t1
FULL OUTER JOIN t2
    ON t1.id = t2.id

This can be rewritten as a UNION of a left join and a right join:

SELECT * FROM t1
LEFT JOIN t2 ON t1.id = t2.id
UNION ALL
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id

In Laravel, we can write the following code to represent the above full outer join:

$second = DB::table('t2')
             ->rightJoin('t1', 't1.id', '=', 't2.id')

$first = DB::table('t1')
            ->leftJoin('t2', 't1.id', '=', 't2.id')
            ->unionAll($first)
            ->get();

Again, I don't know why you think you need two outer joins, but regardless you should be able to adapt the above code and query and use it for your situation.

References:

Community
  • 1
  • 1
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
-1

this code works for me to make a full join:

$second = DB::table('t1')
             ->rightJoin('t2', 't1.t2_id', '=', 't2.id')

$first = DB::table('t1')
            ->leftJoin('t2', 't1.t2_id', '=', 't2.id')
            ->union($first)
            ->get();
m.elewa
  • 187
  • 1
  • 9