Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 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 October 16th, 2006, 11:57 PM
Registered User
 
Join Date: Oct 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to royaloba
Default Query Table NEED HELP

----------------------------------------------
| Date | TimeIn | CardNumber | TimeOut |
----------------------------------------------
2002-05-02 |21:30:12 | 13543451 | 21:30:12
2002-05-02 |21:30:22 | 13543451 | 21:30:22
2002-05-02 |21:30:48 | 45634546 | 21:30:48
2002-05-02 |21:30:55 | 45634546 | 21:30:55
2002-05-02 |21:31:19 | 45634546 | 21:31:19
2002-05-02 |21:31:59 | 13543451 | 21:31:59
2002-05-02 |21:32:06 | 13543451 | 21:32:06
2002-05-02 |21:32:08 | 13543451 | 21:32:08


hello guys i have a table above, i want to query the table and select only the firt TIMEIN and the last TIMEOUT base on their CardNumber and Date and sacde in to another table...i want to have an output like this

----------------------------------------------
| Date | TimeIn | CardNumber | TimeOut |
----------------------------------------------
2002-05-02 |21:30:12 | 13543451 | 21:32:09 |
2002-05-02 |21:30:48 | 45634546 | 21:31:19 |

i'll be very thankfull if can somebody provide me a sample code



 
Old October 18th, 2006, 11:56 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can this several ways

One way is to do a union, with one query returning the first, and the other query returning the last.
Select * From ThisTable Where TimeIn = (Select Max(TimeIn) From ThisTable)
Union
Select * From ThisTable Where TimeOut = (Select Max(TimeOut) From ThisTable)

Of course, this doesn't take into account that there might be two records with exaclty the same time in or time out, and therefore you need to further limit the result for each select in the union to return only the "Top 1" record. This is done differenlty depending on the db you are using.

Woody Z http://www.learntoprogramnow.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
table query dabbler Classic ASP Databases 3 October 7th, 2007 01:08 PM
Which query uses that table? d-fxt Access 3 November 17th, 2006 08:24 AM
Can a Make Table Query produce a Linked table? kronik Access 5 May 16th, 2006 06:17 AM
Make Table query : table in Another Database marnik Access 1 March 19th, 2005 12:39 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





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