1

I have the following tables:

A: id, name, url
B: Aid, number

number can be any int (Aid is the id from table A)

I want to select the name, url from table A and the SUM(B.number) So the results will be something like:

name, url, SUM(B.number)
name, url, SUM(B.number)
name, url, SUM(B.number)
[..]

I need to join them somehow? How do i construct that query?

2 Answers 2

3
SELECT name, url, (SELECT SUM(number) FROM B WHERE B.Aid = A.id) As total
FROM A
Sign up to request clarification or add additional context in comments.

Comments

2
SELECT A.name, A.url, SUM(B.number) 
FROM A
LEFT JOIN B ON A.id = B.Aid 
GROUP BY A.name, A.url

Please test it before cause I might have made a mistake since I got no MySQL DB available at the moment.

Comments

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.