2

My SQL query is:

SELECT* FROM cubes LEFT JOIN xkvs ON cubes.id=xkvs.cube_id WHERE xkvs.cube_id IS NULL

I tried the method from the laravel documentation but always get an error, that xkvs.cubes_id is an unknown column.

How do I write this correctly?

This is my try:

$cubes=DB::table('cubes')
        ->leftjoin('xkvs', function ($join) {
            $join->on('cubes.id', '=', 'xkvs.cubes_id')
                 ->where('xkvs.cubes_id', '=', null);
        })
        ->get();
2
  • Can you try bpaste.net/show/9aa8b948eae2 ? I am posting this as a comment since I've never used laravel, nor eloquent in my life yet. Just a wild guess from the docs. Commented Jul 2, 2018 at 10:58
  • thanks for helping, but this did not work Commented Jul 2, 2018 at 11:03

1 Answer 1

2
DB::table('cubes')
    ->select('cubes.*')
    ->leftjoin('xkvs', 'cubes.id', '=', 'xkvs.cubes_id')
    ->whereNull('xkvs.cube_id')
    ->get();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.