Support the ongoing development of Laravel.io →
Database Lumen

Hi everyone, I'm new here and I need some help. My English is not that good, so I hope my sentences are understandable. I would like to read out two tables. The first table should be output completely and the second table only the matching entries. My code looks like this:

$dbkompetenzen = DB::table('LD_Kompetenzen') ->leftjoin('LD_SHD', 'LD_SHD.KompetenzID', '=', 'LD_Kompetenzen.id') ->where('LD_Kompetenzen.FachID','=',$idfach) ->where('LD_Kompetenzen.ThemenID','=',$idthemen) ->where('LD_SHD.SHDID','=',$shdid) ->select('LD_Kompetenzen.id', 'LD_Kompetenzen.FachID', 'LD_Kompetenzen.ThemenID', 'LD_Kompetenzen.Kompetenz', 'LD_SHD.SHDID', 'LD_SHD.Ergebnis', 'LD_SHD.Stufe', 'LD_SHD.Niveau', 'LD_SHD.Note', 'LD_SHD.Datum', 'LD_SHD.Kuerzel', 'LD_SHD.background') ->get();

Unfortunately I only get 2 rows from the table LD_SHD (there is nothing more). The LD_Kompetenzen table contains 14 rows. I would like to output all 14 lines, if a user (SHDID) has matching entries for the ID "Kompetenzen", then all 14 values should still be output. If there are no SHDID entries, all 14 lines of "Kompetenzen" should be output and the SHDID entries should display "null". I hope my concern is understandable.

Last updated 3 years ago.
0

Can you please try with below.

$dbkompetenzen = DB::table('LD_Kompetenzen') ->leftjoin('LD_SHD','LD_Kompetenzen.id','=', 'LD_SHD.KompetenzID') ->where('LD_Kompetenzen.FachID','=',$idfach) ->where('LD_Kompetenzen.ThemenID','=',$idthemen) ->where('LD_SHD.SHDID','=',$shdid) ->select('LD_Kompetenzen.id', 'LD_Kompetenzen.FachID', 'LD_Kompetenzen.ThemenID', 'LD_Kompetenzen.Kompetenz', 'LD_SHD.SHDID', 'LD_SHD.Ergebnis', 'LD_SHD.Stufe', 'LD_SHD.Niveau', 'LD_SHD.Note', 'LD_SHD.Datum', 'LD_SHD.Kuerzel', 'LD_SHD.background') ->get();

0

I discovered the Join ON function. This makes my project work!

Last updated 3 years ago.

ramiltk liked this reply

1

Sign in to participate in this thread!

PHPverse

Your banner here too?

Sascha saschaschr Joined 11 Jul 2021

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.