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

adamjhn's avatar

Query to get the last registrations is not working properly

I have this query because I want to show in the conference management page some info in a table about the last 3 registrations in a specific conference (the name of the user that did the registration, the quantity of selected registration types and the value of the total prices of the selected registration types):


    <table>
        <thead>
        <tr>
            <th scope="col">User that did the registration</th>
            <th scope="col">Quantity</th>
            <th scope="col">Value</th>
        </tr>
        </thead>
        <tbody>
        @foreach($registrations as $registration)
            <tr>
                <td>{{ $registration->userName}}</td>
                <td>{{$registration->participants_count}}</td>
                <td>{{number_format($registration->totalPrice, 2)}}$</td>
            </tr>
        @endforeach
        </tbody>
    </table>

So there is the manage() method that gets some data and redirect the user to the conference management page with that above data:


     public function manage($id) // $id is the id of the conference
       ...
       $registrations = DB::table('registrations')
       ->join('participants', 'registrations.id', '=', 'participants.registration_id')
       ->join('users', 'users.id', '=', 'registrations.main_participant_id')
       ->join('registration_types', 'registration_types.id', '=', 'participants.registration_type_id')
       ->select(DB::raw('count(participants.registration_id) as participants_count, sum(registration_types.price) as totalPrice, users.name as userName, 
                registrations.created_at'))
      ->where('conferences.id',$conference->id)
      ->groupBy('registrations.id')->orderBy('created_at', 'desc')->get();
    
      dd($registrations)
      ....

      return view('conferences.manage')
             ->with('conference', $conference)
             ->with('registrations', $registrations)
             ->with(...);
        }

But its not working properly. When the conference management page is acessed it shows:


    SQLSTATE[42S22]: Column not found: 1054 Unknown column 'conferences.id' in 
    'where clause' (SQL: select count(participants.registration_id) as participants_count, 
    sum(registration_types.price) as totalPrice, 
    users.name as userName, registrations.created_at from `registrations` 
    inner join `participants` on `registrations`.`id` = `participants`.`registration_id`
    inner join `users` on `users`.`id` = `registrations`.`main_participant_id` 
     inner join `registration_types` on `registration_types`.`id` = `participants`.`registration_type_id` 
     where `conferences`.`id` = 1 
     group by `registrations`.`id`
      order by `created_at` desc)

Tables structure:

      Conferences: id, name, user_id, ...
      Registrations: id, conference_id, user_that_did_registration
      Registration_types: id, name, conference_id, price, ...
      Participants: id, name, surname, registration_type_id

0 likes
1 reply
Snapey's avatar
Snapey
Best Answer
Level 122

You don't have conferences table in your query, so conferences.id does not exist.

You probably meant conference_id - a column on the registration table

1 like

Please or to participate in this conversation.