I think you need the DISTINCT operator.

Assuming you haven't seen it, it works like this. Let's say that your query
asks for a list of all the job titles in your employee table, where the job
title is one of the columns of that table. The employee table looks like
this:

EMPNO  NAME   JOB
1          Smith    Programmer
2          Jones    Analyst
3          Green   Programmer
4          Brown  Analyst
5          Black    Manager

Select empno, job
from employee;

should return exactly the same number of rows as there are in the table.
Each of the result rows will contain the job title from one of the rows read
by the query so you should get this:

EMPNO  JOB
1          Programmer
2          Analyst
3          Programmer
4          Analyst
5          Manager

The result of removing EMPNO from the query should be obvious but here it is
anyway:

select job
from employee;

JOB
Programmer
Analyst
Programmer
Analyst
Manager


Now, in your case, you just want to know the different job titles in the
table and don't care who has that title or how many people have that title.
So, you change the query like this:

select distinct job
from employee

That should give you this:

JOB
Analyst
Manager
Programmer

I haven't actually tried this in MySQL - I mostly use DB2 - but it should
work. It won't take long for you to give it a try to be sure....

Rhino

----- Original Message ----- 
From: "Daniel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 22, 2004 1:04 PM
Subject: Need help finding months with entries


>
> I have a MySQL table with a Date column in format \"YYYY-MM-DD\" and I\'m
trying to figure out a query that would return a list of months that have an
entry in the above table. With output like:
>
> Mar-01, Feb-01, Apr-01 etc...
>
> I\'m still pretty new to MySQL and the date functions are still a bit
confusing to me. Would something like this work?
>
> \"SELECT (DATE_FORMAT( DateCol, \"%b-%Y\") AS MonthWithEntry) FROM
BlogTable;\"
>
> I think that would work but how do I get it to return only 1 row per month
with entries rather than 1 row per entry that month?
>
> Cheers,
>
> Danielb
>
> -- 
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]
>


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to