hi,
I have two tables as given created in SQL srever 2005
Employees
-----------------
>intEid (primary key)
>intLeaveCredit
LeaveApplications
--------------------------
>intSlno (primary key)
>intEid (Foreign key)
>strTypeOfLeave
...
>dteApplicationDate (datetime)
>bolSanctioned (boolean)
now, i need to be able to get max date of each intEid in LeaveApplications with bolSanctioned as false. I need all the fields in the LeaveApplications Table and intLeaveCredit from the Employees table, to be in the resulting joined table.
this is what I have been doing... -
select e.intEid, e.intLeaveCredit, l.strTypeOfLeave, l.dteFrom, l.dteTo, l.strReason, l.dteApplicationDate, l.bolSanctioned
-
from Employees e
-
join LeaveApplications l
-
on e.intEid = l.intEid
-
where l.dteTo = (select max(dteTo) from LeaveApplications where bolSanctioned = 'false' )
-
8 1293
Sorry about the title folks... did that in frustation.. and thank you in advance for any help.
I don't see a problem in your query.
Do you get incorrect result?
You can do the same differently if you wish but you did OK.
[PHP]select Top 1 e.intEid, e.intLeaveCredit, l.strTypeOfLeave, l.dteFrom, l.dteTo, l.strReason, l.dteApplicationDate, l.bolSanctioned
from Employees e
join LeaveApplications l
on e.intEid = l.intEid
where bolSanctioned = 'false'
ORDERR BY l.dteTo desc[/PHP]
I don't get any records. I've made only a couple of test entries in the necessary fields for each table... it gave me a result when i reteived records from only the Leave records table. but what i need is a joined table with all the fields from the LeaveApplications table and the LeaveCredit field from the Employee table.
thank you for replying
It is not a query problem.
Execute following query. Did you get any records? If not it means you don't have matching intEid in both tables.
[PHP]select *
from Employees e
join LeaveApplications l
on e.intEid = l.intEid[/PHP]
If you received result above try to execute query below. If you don't have a result here it means even thou you have matching records none of them is False.
[PHP]Select *
from Employees e
join LeaveApplications l
on e.intEid = l.intEid
where bolSanctioned = 'false'[/PHP]
Sorry for the delay in replying... I was not working. You are correct about the entries I made. I had no record with bolSanctioned as false. I cannot believe I wasted so much time on this... and I would have wasted more time if it weren't for you. Thank you so much.
But I still have a problem. I'm only getting one record with the max date i the whole table. what i needed was the last date for each employee listed in the table. any suggestions? and Thank you once again for helping me...
Try this:
[PHP]select e.intEid, e.intLeaveCredit, l.strTypeOfLeave, l.dteFrom,
l.dteTo, l.strReason, l.dteApplicationDate, l.bolSanctioned
from Employees e
join LeaveApplications l on e.intEid = l.intEid
where l.dteTo = (select max(dteTo) from LeaveApplications where bolSanctioned = 'false' and intEid = e.intEid )
and bolSanctioned = 'false' [/PHP]
thank you iburyak for your help. I finally managed to find a solution without using any join.
this is my solution. Thank you all the same. - select e.intEid , e.intLeaveCredit, l.strTypeOfLeave , l.dteFrom , l.dteTo , l.strReason , l.dteApplicationDate
-
from LeaveApplications l, Employees e
-
where e.intEid = l.intEid
-
and dteTo = (SELECT max(dteApplicationDate) from LeaveApplications l1 WHERE l1.intEid = l.intEid and l.bolSanctioned = 'False')
thank you iburyak for your help. I finally managed to find a solution without using any join.
this is my solution. Thank you all the same. - select e.intEid , e.intLeaveCredit, l.strTypeOfLeave , l.dteFrom , l.dteTo , l.strReason , l.dteApplicationDate
-
from LeaveApplications l, Employees e
-
where e.intEid = l.intEid
-
and dteTo = (SELECT max(dteApplicationDate) from LeaveApplications l1 WHERE l1.intEid = l.intEid and l.bolSanctioned = 'False')
HA HA HA..... :)
Whatever you show is a join just written old way that is not recommended to use in SQL syntax.... LOL
Old syntax for join:
[PHP]from LeaveApplications l, Employees e
where e.intEid = l.intEid[/PHP]
New syntax for join:
[PHP]from Employees e
join LeaveApplications l on e.intEid = l.intEid[/PHP]
Good Luck.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: greg |
last post by:
Discussion is invited on the following proto-PEP.
-------------------------------------------------------------
PEP ??? - Overloadable Boolean Operators...
|
by: Joe |
last post by:
I have a situation where the wrong constructor is being called. I
have defined 2 constructors with different parameter types that are
defined as follows...
class __declspec(dllexport)CColumn :...
|
by: sb |
last post by:
If there is at least one user-defined constructor, no constructors are
implicitly declared.
struct my_vec : public vector<int> {
double foo;
my_vec(size_t n) : vector<int>(2*n) {}
// oops, no...
|
by: peter pilsl |
last post by:
Is there a way to reset the xlog on postgres 7.1 ?
Due to complete & intensive braindamage of sysadmin (=me) the whole
pg_xlog-folder has been emptied on a old 7.1-installation.
pg_resetxlog is...
|
by: David Veeneman |
last post by:
I'm using the new BindingList generic class in a collection class. For those
not familiar with BindingLists, they are similar to generic ArrayLists, but
they implement the IBindingList interface,...
|
by: Christoph Zwerschke |
last post by:
You will often hear that for reasons of fault minimization, you should
use a programming language with strict typing:
http://turing.une.edu.au/~comp284/Lectures/Lecture_18/lecture/node1.html
I...
|
by: BRENDAMAGE |
last post by:
can anyone hlp on this...
how to trap empty string(value) before it saves to database...
this one id like to happen...
lastname
firstname
middlename
|
by: J de Boyne Pollard |
last post by:
HSfgets() is standard in C file I/O.
HS>
HSThe only issue you need to pay attention too, is RAW
HS(binary) vs COOK mode. It will relate the EOL (end
HSof line) definitions of MS-DOS (<CRL><LR>)...
|
by: copx |
last post by:
In "Learning Standard C++ as a New Language" Bjarne Stroustrup claims that
properly written C++ outperforms C code. I will just copy his first example
here, which is supposed to demonstrate how C++...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |