If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SELECT problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-18-04, 15:00
jmut jmut is offline
Registered User
 
Join Date: Mar 2004
Location: Bulgaria
Posts: 22
SELECT problem

The tables used in the SELECT:
CREATE TABLE `Salespeople` (
`snum` int(11) NOT NULL default '0',
`sname` char(10) NOT NULL default '',
`city` char(10) default NULL,
`comm` decimal(10,2) default NULL,
PRIMARY KEY (`snum`)
) TYPE=InnoDB
--------------------------------------------------------
CREATE TABLE `Orders` (
`onum` int(11) NOT NULL default '0',
`amt` decimal(10,2) default NULL,
`odate` date NOT NULL default '0000-00-00',
`cnum` int(11) NOT NULL default '0',
`snum` int(11) NOT NULL default '0',
PRIMARY KEY (`onum`),
KEY `cnum` (`cnum`),
KEY `snum` (`snum`),
CONSTRAINT `0_57` FOREIGN KEY (`snum`) REFERENCES `Salespeople` (`snum`),
CONSTRAINT `0_58` FOREIGN KEY (`cnum`) REFERENCES `Customers` (`cnum`)
) TYPE=InnoDB |

According to the book I am reading ("Mastering SQL" -hence not for MySQL!!) the following statements should produce the same result. But they don't. I have no idea why. I am using 4.0.15 and I am thinking this might be a syntax issue (differing from the standard).
------------------------------------------------------------------------
1.
SELECT sname, onum
FROM Salespeople NATURAL LEFT OUTER JOIN Orders
WHERE odate = '2003-03-10' ORDER BY 1;
------------------------------------------------------------------------
2.
SELECT sname, onum
FROM Salespeople s LEFT JOIN Orders o
ON odate = '2003-03-10' AND s.snum = o.snum
ORDER BY 1;
------------------------------------------------------------------------
Both queries should do the same thing only written in different way. Is that so.
Here are the results from the queries:
--------------------------------------------------------------------------
1.
+--------+------+
| sname | onum |
+--------+------+
| Motika | 3002 |
| Peel | 3003 |
| Rifkin | 3001 |
| Rifkin | 3006 |
| Serres | 3005 |
+--------+------+
-------------------------------------------------------------------------
2.
+---------+------+
| sname | onum |
+---------+------+
| Axelrod | NULL |
| Motika | NULL |
| Peel | NULL |
| Rifkin | NULL |
| Serres | NULL |
+---------+------+

Any ideas what the problem is? Thanks in advance. btw the first query seems to produce the correct results.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On