Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LEFT question

Status
Not open for further replies.

CryoGen

MIS
Apr 15, 2004
86
US
I'm sure this is easy, but I can't figure it. I keep getting an error on this saying that 'Initial' is an unknown column in the where clause.

Code:
  SELECT    system, acronym, id, year, cat, acronym, LEFT('system', 1) AS initial
  FROM      csap
  WHERE     year = '2004' AND initial = 'a'
  ORDER BY  system;
 
Does the use of a HAVING clause require a GROUP BY clause as well? My DuBois book has one example and it uses that. How would it be structured?
 
Thanks, but I don't know how to structure the query using HAVING.

I need to be able to have the query search on the first letter in the system column as well as the date (the 'a' and the year are static, but will be dynamic in CF).
 
OK, that works with v5.0.2, but not with the version 4.10 that I'm using. Is there another way to get where I need to go without creating another column?
 
I'm using MySQL 4.1.10, and the HAVING clause works as I described.

Are you getting an error or screwy behavior? I noticed that in my query, which was based on yours, the LEVT() invocation reads:

LEFT('system', 1)

This is incorrect, as the first parameter of the LEFT() function is the literal string "system", not the column name system. This is because of the single quotes.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
You're right. I removed the quotes and the query ran fine. Thanks for the help.
 
On my MySQL 4.1.10 installation, wht the table "foo" with the following data:

[tt]+------+--------+------+
| pkid | system | year |
+------+--------+------+
| 1 | aaaa | 2000 |
| 2 | bbbb | 2000 |
| 3 | cccc | 2000 |
| 4 | aaaa | 2001 |
| 5 | bbbb | 2002 |
| 6 | cccc | 2003 |
| 7 | dddd | 2004 |
| 8 | aaaa | 2004 |
+------+--------+------+[/tt]


The query:

Code:
select system, year, left (system, 1) as initial
from foo
where year=2004
having initial = 'a'

works and returns:

[tt]+--------+------+---------+
| system | year | initial |
+--------+------+---------+
| aaaa | 2004 | a |
+--------+------+---------+[/tt]


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top