954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

sql query

i have three table

1st viewleave
2nd applyleave
3rd personal

based on the leaveid in viewleavetable i wnt to fetch the spid in the second table,based on the spid i want to select spid email address........please tell how to do tat..
CREATE TABLE `viewleave` (
`leaveid` varchar(25) NOT NULL,
`message` varchar(500) NOT NULL
)

CREATE TABLE `applyleave` (
`leaveid` int(11) NOT NULL auto_increment,
`spid` varchar(25) NOT NULL
PRIMARY KEY (`leaveid`)
)

CREATE TABLE `personal` (
`spid` varchar(25) NOT NULL,
`email` varchar(60) NOT NULL,

)

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

select email from personal where spid=(select spid from applyleave where leaveid=(select leaveid from viewleave where leaveid="specify your leaveid here"))

Hi.. Try this and let me know if this works..

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Subquery returns more than 1 row

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

That means there are many records with the same spid. You can change the above query to,
select email from personal where spid IN (select spid from applyleave where leaveid IN (select leaveid from viewleave where leaveid="specify your leaveid here"))

Cheers.

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

thanks it is working.........

i have a form where the candidate id,from-date and to-date will be given by the user..based on tat i want to exact data from the table

SELECT * from attend where day1 between '$from' and '$to';

i am able to extract date based on the condition given by the user,i want to exact on a particular id's date...how to do tat

this is my table...........

CREATE TABLE `attend` (
`spid` varchar(50) NOT NULL,
`day1` date NOT NULL,
`time1` varchar(50) NOT NULL
)

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

just add another condition !
SELECT * from attend where (day1 between '$from' and '$to') and spid='$id' :)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

thanks......

kings
Junior Poster
107 posts since Nov 2007
Reputation Points: 3
Solved Threads: 2
 

you are welcome :)

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Hi friends

Please chk this query this also help for you
SELECT *
FROM applyleave a1, viewleave v1, personal p1
WHERE a1.leaveid = v1.leaveid
AND a1.spid = p1.spid
LIMIT 0 , 30

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You