I’m trying to connect a relation table, and and get the max value
$query->joinWith('hotelPrices')
->andWhere([HotelPrice::tableName() . '.price' => $form->prices])
->max(HotelPrice::tableName() . '.price');
but i get this error
SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: ‘hotel_price’
how to me in this case to use alias?
2
Answers
The error message indicates that you have used the same table alias (‘hotel_price’) in multiple places in your query. You can use a different alias for the ‘hotel_prices’ table in your join statement.
As stated in documentation, you can add alias by adding it to relation name. In your case: