
June 24th, 2003, 07:24 PM
|
|
|
|
Join Date: Apr 2007
Posts: 7
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
yet another weird sql statement
Hello,
Ok, I am need of help with a query statement. I am using mssql. I also have tables with fields: YEAR, MONTH, f1, f2, f3... So what happens is a specify a monthly and a yearly range, so i can grab particular months from the specified years. (This statement works fine). The problem is however, I would like to query from multiple tables as a single result. All the tables have the same field names. All I want to be able to do is grab a single column, say 'f1', from multiple tables within the monthly and yearly ranges. This is basically what I have now:
SELECT t1.f1, t2.f1 FROM t1, t2 WHERE YEAR BETWEEN $begin_year AND $end_year AND MONTH BETWEEN $begin_month AND $end_month
however, it tells me that YEAR and MONTH are ambiguous, which they are. So, I specified the YEAR and MONTH columns as t1.YEAR and t1.MONTH. But my results get really screwed up. I only get results for t1. Is there anyway to generically specify, that you want YEAR and MONTH from every table in the query???
So, I'm kinda stuck.
Your help is much appreciated, thanks in advance.
Bubba
|