Subject | RE: [firebird-support] Help with query, bit confused |
---|---|
Author | Nigel Weeks |
Post date | 2005-12-27T22:23:09Z |
> I want to query the last 3 records to find out the number that have aLet's break this query apart a little. I'm guessing that the 'LOGGED' field
> status of Failed. I thought the query below would work?
>
> SELECT COUNT(STATUS) FROM CONTACT_LOGIN_LOG
> WHERE STATUS='Failed' AND LOGGED IN (
> SELECT FIRST 3 LOGGED FROM CONTACT_LOGIN_LOG
> WHERE LOGIN_NAME='joe' ORDER BY LOGGED DESC);
>
> Which would accomplish my goal. Return the number of rows
> with a failed
> status out of the last 3 rows of data. With the number being returned
> being no greater than 3.
>
> However it does not work that way at all. I get more than 3 rows with
> the query? I do not understand why the LOGGED IN select_list does not
> work? Should the query not require both conditions to be met? Unless
> LOGGED is in the 3 last rows selected. It should not matter if it's
> status is failed or not. Since only one of the 2 conditions is true?
>
is a timestamp.
Looking at the inner part of the query, this will return three of the
'LOGGED' field, in descending order. Lets pretend that they are:
'2005-12-24 9:50:00', '2005-12-24 9:52:00', '2005-12-25 00:05:00', and the
person logging in was joe(which has no effect when it comes to the next bit)
Now the outer query.
In plain english, this is:
Get me the total number of statuses from the contact_login_log table where
status = failed, AND any logins have occured on any of the following
timestamps: '2005-12-24 9:50:00', '2005-12-24 9:52:00', '2005-12-25
00:05:00'
So, if fifty people also tried to log in on those times as well, they'll be
counted by your outer section as well. The login_name = 'joe' has no effect
on the outer section.
Can you re-describe what you actually want it to give you, and we'll see if
we can recommend a query.
If you want the last three failed logins:
select first 3 login_name, logged from contact_login_log where
status='Failed' order by logged desc;