SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 29th, 2003, 02:54 AM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
retrieving latest data.

hi. i need to retrieve e latest data from a table.. but am nt sure how to do it...
here's how it goes...(by e way i'm using ms access) i have a table with 10 schools.. in every school, there's 8 stalls . and in every stall, i have 1 current owner n a few previous owners.

k.. n how do i retrieve e current owners of every stall when i click on e school? tat means when i click e school, each stall will only show e current or latest owner to date. thanks...

Reply With Quote
  #2  
Old October 29th, 2003, 11:27 AM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Is all this information in one table or multiple tables? What is you general DB Structure

S-

Reply With Quote
  #3  
Old October 29th, 2003, 11:45 AM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
it's all in one table... i dun get what u mean by general db structure.. or mayb i should put my screen shot up? by e way i'm using ms access

Reply With Quote
  #4  
Old October 29th, 2003, 12:06 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
You should be able to create a basic select statement that should bring back the information that you need. Just include the school id in the Where part of the statment

"SELECT * from SCHOOLTABLE WHere SCHOOLTABLE.SCHOOLID = 'SCHOOL1';"

S-

Your screen shot would help me give you a more accurate statement

Reply With Quote
  #5  
Old October 29th, 2003, 12:10 PM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
erm... wad i mean was to return table with e latest owner of all the stalls of tat particular shcool.. tat means should have stall1 - latest owner, stall 2 latest owner... and soo on.. sorry

Reply With Quote
  #6  
Old October 29th, 2003, 12:14 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Better include your screen shot

s-

Reply With Quote
  #7  
Old October 29th, 2003, 09:57 PM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
erm.. think i can't include it.. cos i dun have a server or account to store my pics.. anyway.... i shall post it this way..

GIVEN TABLE:

<u>Name</u>|| <u> stallnumber</u> ||<u>datejoined</u> || school

abc || stall 1 || 23/06/1984 || nss

cde || stall 1 || 23/06/1999 || nss

xyz || stall 2 || 23/09/1999 || nss

nick || stall 2 || 23/06/2003 || nss



but this is what i wana retrieve from this table.

<u>Name</u> &nbsp<u> stallnumber</u> &nbsp<u>datejoined</u>&nbsp school

cde &nbsp stall 1 &nbsp 23/06/1999 &nbsp nss

nick &nbsp stall 2 &nbsp 23/06/2003 &nbsp nss




*note.. only e latest owner with reference from e datejoined from the same stall is retrieved.

Last edited by shawnleong : October 29th, 2003 at 10:01 PM.

Reply With Quote
  #8  
Old October 30th, 2003, 12:38 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Have fun with this

If you need a copy of the DB I created this is let me know

SELECT [Shawnleong].[Name], [Shawnleong].[StallNumber], [Shawnleong].[DateJoined], [Shawnleong].[School]
FROM
Shawnleong
INNER JOIN
[SELECT Shawnleong.StallNumber, Shawnleong.School, Max(Shawnleong.DateJoined) AS DateJoined1
FROM Shawnleong
GROUP BY Shawnleong.StallNumber, Shawnleong.School
HAVING (((Shawnleong.School)='nss'))]. AS PLAY_GROUP
ON ([PLAY_GROUP].[School]=[Shawnleong].[School]) AND ([PLAY_GROUP].[DateJoined1]=[Shawnleong].[DateJoined]) AND ([PLAY_GROUP].[StallNumber]=[Shawnleong].[StallNumber]);

S-

Reply With Quote
  #9  
Old October 30th, 2003, 10:43 PM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
hmm... kinda blur down here,,,... or mayb i'll send u my table? i'm nt really sure down her.e.

Reply With Quote
  #10  
Old October 30th, 2003, 11:15 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Here is a database set up with a table as you stated
__________________________________________

Name|| stallnumber ||datejoined || school

abc || stall 1 || 23/06/1984 || nss

cde || stall 1 || 23/06/1999 || nss

xyz || stall 2 || 23/09/1999 || nss

nick || stall 2 || 23/06/2003 || nss

___________________________________________

The SQL Statement works, it is saved in query1 (you need to use SQL view)

Basically itis a two part query in one statement; you have a query that is grouped to give you the max Joindate of each school/stall combination. Then you join this query back to the orginal table to get the latest name of the person in charge of each stall. All you need to do is change the part the references which school.

S-

Reply With Quote
  #11  
Old November 3rd, 2003, 10:33 PM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
sorry but wad's play_group?

Reply With Quote
  #12  
Old November 3rd, 2003, 11:11 PM
sbaxter sbaxter is offline
Moderator: Access, SQL
ASP Free God (5000 - 5499 posts)
 
Join Date: Oct 2003
Posts: 5,126 sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level)sbaxter User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 1 h 2 m 51 sec
Reputation Power: 13
Play-Group is an Alias table (Some think of it as a virtual table). I name the nested select statement Play_group so it can be reference in other parts of the Statement(noticed the "AS PLAY_GROUP" at the end of the nested select statement).

S-

Reply With Quote
  #13  
Old November 4th, 2003, 12:22 AM
shawnleong shawnleong is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 19 shawnleong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m 28 sec
Reputation Power: 0
erm.. i need to add some more headers... how do i do so using sql? n how do i retrieve e header n line them up... as in...

name value1
stallnumber value2
datejoined value3
school value4

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > retrieving latest data.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |