7 messages in com.mysql.lists.mysqlLEFT JOIN again... Although, this ti...| From | Sent On | Attachments |
|---|---|---|
| Chris Knipe | 16 Jun 2002 06:43 | |
| Peter Normann | 16 Jun 2002 08:42 | |
| Peter Normann | 16 Jun 2002 08:44 | |
| Chris Knipe | 16 Jun 2002 09:59 | |
| Peter Normann | 16 Jun 2002 10:34 | |
| Chris Knipe | 16 Jun 2002 10:37 | |
| Peter Normann | 16 Jun 2002 10:59 |
| Subject: | LEFT JOIN again... Although, this time I think it's a design flaw rather than a query one....![]() |
|---|---|
| From: | Chris Knipe (sav...@savage.za.org) |
| Date: | 06/16/2002 06:43:07 AM |
| List: | com.mysql.lists.mysql |
Hiya again,
Ok, based on all the info, feedback and help I got the last time, I was able to construct the following query:
mysql> SELECT weather_data.Temp, -> weather_locations.Name -> FROM weather_data -> LEFT JOIN weather_data ON -> weather_locations.MetarCode = weather_data.Site -> WHERE weather_locations.MetarCode IS NULL; ERROR 1066: Not unique table/alias: 'weather_data'
The tables look as follows: mysql> DESCRIBE weather_data; +---------------+--------------+------+-----+---------------------+--------- -------+ | Field | Type | Null | Key | Default | Extra | +---------------+--------------+------+-----+---------------------+--------- -------+ | EntryID | bigint(20) | | PRI | NULL | auto_increment | | RawData | varchar(250) | | MUL | | | | Date | datetime | | MUL | 0000-00-00 00:00:00 | | | Site | varchar(4) | | MUL | | | | WindSpeed | tinyint(4) | YES | MUL | NULL | | | WindDirection | varchar(250) | YES | MUL | NULL | | | Temp | tinyint(4) | YES | MUL | NULL | | | DewPoint | tinyint(4) | YES | MUL | NULL | | +---------------+--------------+------+-----+---------------------+--------- -------+ 8 rows in set (0.29 sec)
mysql> DESCRIBE weather_locations; +------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | LocationID | tinyint(4) | | PRI | NULL | auto_increment | | MetarCode | varchar(4) | | UNI | | | | Name | varchar(250) | | UNI | | | | Province | varchar(250) | YES | MUL | NULL | | +------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.03 sec)
The basic background.... It's used to compile a history of weather information on approximately 75 locations in my country (ala .za). The weather_locations table, holds unique rows describing the various locations of the weather stations. In this table, MetarCode is a 4 character key identifing the weather station, while Name represents the physical location (such as the Town or airport).
In my weather_data table, I save the actual weather data. I cannot use UNIQUE keys in this table, because I need to build up a history of the weather changes. In this table, Site represents the same weather station identifier as MetarCode in the weather_locations table. So, I'm trying to accomplish my JOIN on weather_locations.MetarCode and weather_data.Site.
Basically, the data that I want to have returned: SELECT weather_locations.Name, weather_data.Temp FROM weather_data WHERE weather_data.Site='FACT';
Yes, this is a broken query, but I think it would give a good idea of what I want.... I want the weather site's name from the weather_locations table, plus whatever column I want from the weather_data table (such as temprature, WindSpeeds, WindDirection, etc).
Bah...
While typing this and playing arround some more, I got it working....
SELECT weather_data.Temp AS Temp, weather_locations.Name AS Name FROM weather_locations LEFT JOIN weather_data ON weather_locations.MetarCode = weather_data.Site WHERE weather_data.Site='FACT' OR weather_data.Site='FADN' OR weather_data.Site='FAJS';
Thanks anyways :-)




