Well, I have a database from a client where tables have not a good relationship, is a mess. The problem to get the info I need is that the fields I need to relate the tables are not related with the tables I am going to use.
I'll make myself clear:
There are 3 tables: visits, coffees and payments.
Table coffees has payment_id. Table visits has coffee_id. Table payments has no ids!!
I want to know how many visits had coffee and how many payments were made for each coffee..
The result should be something like:
VISITS | COFFEE | PAYMENTS
8234 | MOCHA | 829
So, how am I going to know all the payments that were made, what coffee it was and how many visits it had?
Might be obvious but I am kind of overwhelmed with the same thing.
Thanks everyone for your help!
To get visits for each coffee:
To get payments for each coffee:
To get them both in a single query: