J
J
Jedi2020-06-11 17:18:43
Laravel
Jedi, 2020-06-11 17:18:43

How not to repeat entries with the same foreign_id?

user_cars(id, user_id, car_id, expired_at). Table for car rental.

It could be that one user rented the same car several times. I would like to get data on how many times the car has ended up being rented out. I don't know how to correctly implement a user_id repetition check... I can use foreach, but I want to read your version. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2020-06-11
@KingstonKMS

Response to the header: in order not to repeat entries with the same car_id, it must be made unique.
With the current situation:

select count(car_id) as count from user_cars where user_id = <id> group by car_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question