Michael

do the first join
people.zip = city.zip

yo get 2 rows from people 1 and 3

notice there is no peopleid 2 from first join so correct answer is to retun
null

Rick

-----Original Message-----
From: Michaël Delorme [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 07, 2001 11:00 AM
To: [EMAIL PROTECTED]
Subject: Query and join problem with null values


Hi guys

I have a problem on a SQL query : I got no records selected. Below
is a sample of my 2 tables :

****
A table identifying people, containing their adress therefore a ZIP
code. However for some people I don't have their adress, so no ZIP code :

Table People
+----------+------+
| PeopleID | zip  | ...
+----------+------+
| 1        | 1    |
| 2        | Null |
| 3        | Null |
| 4        | 3    |
|         ...     |
+----------+------+

****
 Another table describe ZIP codes and cities :

Table City
+-----+------+
| zip | city | ...
+-----+------+
| 1   | aaa  |
| 2   | bbb  |
| 3   | ccc  |
| 4   | ddd  |
| 5   | eee  |
|    ...     |
+-----+------+

Here is my query :

SELECT
  people.peopleId,
  people.zip,
  city.city

FROM
  people,
  city

WHERE
  people.zip = city.zip
  and people.peopleId = "2";

I don't get any selection... wheras I expect :
+----------+------+------+
| PeopleID | zip  | city |
+----------+------+------+
| 2        | Null | Null |
+----------+------+------+


Where am I wrong ?
Thanks in advance
Michael


Here are the table definitions :

CREATE TABLE `people` (
  `peopleId` tinyint(1) unsigned NOT NULL auto_increment,
  `zip` varchar(255) default NULL,
  PRIMARY KEY  (`peopleId`)
)

CREATE TABLE `city` (
  `zip` tinyint(1) unsigned NOT NULL auto_increment,
  `city` varchar(255) default NULL,
  PRIMARY KEY  (`zip`)
)


__________________________________________
Michael Delorme
GIS Manager
French Mediterranean Botanical Conservancy
mailto:[EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail
<[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to