I have two table user and contact, each user can have multiple contacts
I want to draw a graph (camembert) with JFreeChart(java library) to present the number of contacts that has each user
I tested :
select u.name, sum(c) from user u, contact c
but I have
unknown column c in field list
here are the structures of tables :
utilisateur = idutilisateur, identifiant, motdepasse, nom, prenom
contact = idcontact, …………, idutilisateur
How can I achieve that,
and also, please give me links to tutorials for learning to make queries like that because always I have this problem and I find only basic tutorials
thank you in advance
You need to reference the column of the table that you’re trying to count, not just the table itself.
if you try:
You can count all records that have a value in the ID field. If this is a primary key, then all records should have this field. Note the change from
sumtocount.This won’t fully solve your problem. You also have to let sql know that the two tables are related by joining:
Put this after the
from user uinstead of, contact cFor a good start to learning sql, try here: http://www.w3schools.com/sql/default.asp