Wrox Programmer Forums
|
MySQL General discussion about the MySQL database.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the MySQL section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2006, 02:19 AM
Registered User
 
Join Date: Feb 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default subquery

what is the syntax of writing subquery in my sql.

when i write this query
"select EmpID, EmpName from Employees where EmpID IN (select EmpID from rightlinks where RightID=3)"

it gives me the error

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select EmpID from rightlinks where RightID=3)' at line 1

khansa
 
Old February 21st, 2006, 02:49 AM
Authorized User
 
Join Date: Apr 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jmukesh Send a message via Yahoo to jmukesh
Default

Check whether your version of mysql supports sub queries.
Subquery support was added in version 4.1.

If your version of mysql does'nt support subqueries.
then a workaround for your particular case..



Query 1 >> "select EmpID from rightlinks where RightID=3"
building up a string with your first Query like

11,12,13,14 which are EmpID seperated by comma and use the
generated string in the next query.

Query 2>>"select EmpID, EmpName from Employees where EmpID IN (11,12,13,14 )"

~Regards
jmukesh









Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble with subquery ghall202 Access 1 July 9th, 2008 01:55 PM
Subquery debbiecoates SQL Server 2000 4 June 25th, 2008 03:49 AM
Subquery as table brettk_1 Oracle 1 January 22nd, 2007 02:10 PM
Do i have to use a subquery, if yes then how? code_lover SQL Language 2 January 2nd, 2007 02:22 PM
Help...subquery problem Twistdmojo Classic ASP Databases 4 September 14th, 2006 11:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.