Mysql: multiple tables join

Posted 1 year ago by keevitaja

Hello!

I have 2 tables:

entities:

id

statuses:

id
entity_id
status

Each entity can have many statuses and i need to select only the entities that have 'paid' status and do not have 'cancel' status. How do i do a proper join for that?

Not using eloquent, but raw queries.

Example:

entities: id 7
entities: id 8
entities: id 9
entities: id 10
statuses: id 1, entity_id 7, status 'paid'
statuses: id 2, entity_id 7, status 'canceled'
statuses: id 3, entity_id 8, status 'paid'
statuses: id 4, entity_id 10, status 'onhold'

Only entiry with the id of 8 will be selected once.

Please sign in or create an account to participate in this conversation.