0

I have two tables. One called HOSTS and one called GUESTS. The HOSTS table consists of:

* hid
* firstname
* lastname
* email

hid is the unique Host Identifier which is an INTEGER, primary key and auto-incremented.

The GUESTS table consists of:

* gid
* hid
* gfname
* glname

gid is the unique Guest Identifier which is an INTEGER, primary key and auto-incremented.

The desired output is to show on each row the HOSTS and a sum total (figure) of guests each host has.

firstname lastname email "tot num of guests"

How do one accomplish this?

1 Answer 1

3

Join the tables and then group the results:

SELECT   HOSTS.*, COUNT(gid)
FROM     HOSTS LEFT JOIN GUESTS USING (hid)
GROUP BY hid
Sign up to request clarification or add additional context in comments.

3 Comments

Can I ask for an even more advance query here or should I create a new question?
@Andreas: You should really ask a new question.
I've created a new post. Hopefully you can help me out with that one too

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.