thedarkside
thedarkside

Reputation: 11

SUM and SELECT ALL

I need a correction please

SELECT *, SUN(mytable2.quantite)
FROM mytable1 
INNER JOIN mytable2 
ON mytable1.id = mytable2.id_table_article

I want to select all columns and SUM one column. How I can do that please ?

I have a problem because I think SUM works with ExecuteScalar and SELECT * works with ExecuteReader() :( how I cant fusion this result because I need to show this result at on my listview so I need one request :/ I work with SQLIte

Upvotes: 1

Views: 7152

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269493

I suspect you want every column from mytable1 and the corresponding sum from mytable2. If so, you can use a subquery:

SELECT t1.*,
       (SELECT SUM(t2.quantite)
        FROM mytable2 t2
        WHERE t1.id = t2.id_table_article
       ) as quantite
FROM mytable1 t1;

Upvotes: 2

Related Questions