[thelist] SQL SELECT Question
Jon Haworth
jhaworth at witanjardine.co.uk
Tue Dec 10 09:54:01 CST 2002
Hi Burhan,
> how do you write a select statement so it
> returns only a list of all values in one column.
[...]
> I then thought that if I gave a conditional that's
> always true, it might work, ie. "SELECT someColumn
> FROM someTable WHERE 1=1", but was told that it didn't work.
It should do... you don't even need the conditional (just "SELECT someColumn
FROM someTable")
This should produce something like
+------------+
| someColumn |
+------------+
| foo |
| foo |
| foo |
| foo |
| bar |
| bar |
| baz |
+------------+
If you just wanted a list of individual values that occur in the column, but
not repeated over and over again, try
SELECT DISTINCT someColumn FROM someTable
which should produce:
+------------+
| someColumn |
+------------+
| foo |
| bar |
| baz |
+------------+
And if you want a count of each value, try
SELECT DISTINCT someColumn
, COUNT(someColumn) AS Count
FROM someTable
GROUP BY someColumn
which should give you:
+------------+-------+
| someColumn | Count |
+------------+-------+
| foo | 4 |
| bar | 2 |
| baz | 1 |
+------------+-------+
Cheers
Jon
More information about the thelist
mailing list