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 > Error Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-24-08, 20:23
magfiroh magfiroh is offline
Registered User
 
Join Date: Jun 2008
Posts: 3
Error Query

I have one table (tbl_employee) with many relations (tbl_relation), you can see it below :
---------------------
SELECT
tbl_employee.NAME,
tbl_employee.DATEOFBIRTH,
tbl_relation.CODEDESC
FROM
tbl_employee
INNER JOIN tbl_relation ON (tbl_employee.GENDER = tbl_relation.CODENAME)
AND (tbl_employee.INTEREST = tbl_relation.CODENAME)
AND (tbl_employee.YEARIN = tbl_relation.CODENAME)
WHERE
(tbl_relation.CODE = '01') AND
(tbl_relation.CODE = '02') AND
(tbl_relation.CODE = '03')
-------------------------------------------------
I have an error when I execute my query.
Is my query correct? Help me, please ..
Reply With Quote
  #2 (permalink)  
Old 06-24-08, 21:24
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
an error, eh?

perhaps you might share with us what that error was

in any case, the query will not produce any results

the WHERE clause specifies that each tbl_relation.CODE value must be equal to three different values at the same time

clearly, this is impossible

however, if you change the ANDs to ORs, then the WHERE clause makes sense

but the ON clause of the join suffers from the same problem

you want tbl_relation.CODENAME to be equal to three different tbl_employee column values

clearly, this is only possible when those three values are all equal to each other

and GENDER = INTEREST = YEARIN, while not strictly impossible, doesn't make much sense either
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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