Jump to content


Photo

pbm wit simple sub query


  • Please log in to reply
1 reply to this topic

#1 shan_cool

shan_cool
  • Members
  • PipPipPip
  • Advanced Member
  • 53 posts
  • LocationChennai,India

Posted 03 March 2006 - 08:37 AM

Hi all,
i hav an error in my subquery


SELECT * FROM HR_Emp_Det WHERE Emp_LName=(select Emp_LName FROM `HR_Emp_Det` WHERE Emp_Id='368')


it shows me,
You have an error in your SQL syntax near 'select Emp_LName FROM `HR_Emp_Det` WHERE Emp_Id='368') LIMIT 0, 30' at line 1


how to make it? am using mysql 3.23

Rgds,
Shan



#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 March 2006 - 07:19 PM

No subqueries in 3.23 -- rewrite it as a JOIN (UNTESTED):

SELECT h1.* FROM HR_Emp_Det AS h1, HR_Emp_Det AS h2 WHERE h1.Emp_LName = h2.Emp_LName AND =h2.Emp_Id='368'

I'm assuming here that you have an index on Emp_LName. BTW, I don't know where your LIMIT clause came from.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users