Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

xfirebg's avatar

Joins with alias

Hello I have a little problem. I need to joing 2 by 2 columns from different tables. But it does not work:

  ->leftJoin('q_prelivnik', 'nivo_prelivnik.date1+nivo_prelivnik.time1', '=', 'q_prelivnik.date1+q_prelivnik.time1')

the full code of query:

  $students = BelmekenKota::whereBetween('nivo_prelivnik.date1', $dateScope)
  ->selectRaw('(nivo_prelivnik.date1+nivo_prelivnik.time1) as timestamp,izch_nivo,q_prelivnik.debit, q_prelivnik.date1, q_prelivnik.time1,nivo_prelivnik.id,q_prelivnik.id')
  ->leftJoin('q_prelivnik', 'nivo_prelivnik.date1+nivo_prelivnik.time1', '=', 'q_prelivnik.date1+q_prelivnik.time1')
  ->orderBy('timestamp', 'ASC')
  ->get();

I tryed with:

  ->leftJoin('q_prelivnik', 'nivo_prelivnik.date1+nivo_prelivnik.time1 as timestamp', '=', 'q_prelivnik.date1+q_prelivnik.time1 as timestamp2')

and

  ->leftJoin('q_prelivnik', 'timestamp', '=', 'timestamp2')

Failed again.

Any idea ho to do it?

0 likes
1 reply
xfirebg's avatar

I will try to explain more. I have 2 tables. Each table have two same columns first: "date1"(example: 26/08/2019) and "time1" (example: 09:51). I need to inner join them like this: firsttable(date1+time1) = secondtable(date1+time1). The issue is that the function "join" does not work with two columns but only with one. I hope you understand me... thanks

Please or to participate in this conversation.