[thelist] counting frequency of distinct values in MSSQL

rudy rudy937 at rogers.com
Mon Sep 15 16:12:18 CDT 2003

> Would I use a join statement? I keep getting syntax errors when
> I try this and variations (using MySQL).
> SELECT column, foreign_column,
> COUNT(column)
> FROM table, foreign_table
> GROUP_BY column
> JOIN ON foreign_table
> WHERE column = foreign_column;

john, you need to make sure the non-aggregate columns in the SELECT list are
all in the GROUP BY

you also need to straighten out some of the other clauses

the GROUP BY goes at the end, the ON should ideally link two columns, one
from each of the tables being joined, which appears to be what you've got in
the WHERE, which, when using JOIN syntax, should contain only filter
conditions, not join conditions

i realize this could all be somewhat overwhelming for someone new to sql

> Anyone know of any good (simple;-) tutorials about getting data
> from two tables (queries using foreign keys)?


there are a bunch of other links on my site --



More information about the thelist mailing list