0

I've 2 table:

**Table A**              **Table B**
idTableA                 idTableB
Code                     idTableA
Description              Description

In Table B I can have more rows linked to table A.

So I need a query who return all table A's columns and COUNT(*) FROM Table B WHERE A.idTableA=B.idTableA

I tried this, but doesn't works:

SELECT A.*, B.COUNT(*) FROM TableA A LEFT JOIN TableB B ON A.idTableA = B.idTableA

1 Answer 1

1

This is the correct syntax:

SELECT A.*, COUNT(B.idTableA)
FROM TableA A LEFT JOIN
     TableB B
     ON A.idTableA = B.idTableA
GROUP BY A.idTableA;

You seem unfamiliar with SQL. You should understand join and group by. These are fundamental concepts in the language.

Sign up to request clarification or add additional context in comments.

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.