473,385 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Top Value Per Unique ID?

Hi There

Trying to figure out how to do this was hoping for some advice.

I have two tables. The first holds the store details with store id, store name etc. The second table holds the Store Status eg new, lfl, refit, resite and so on.

I would like to run a query which finds the "top" value per store id.

Any help greatly appreciated!


Many Thanks


Dan
Dec 19 '07 #1
8 1454
NeoPa
32,556 Expert Mod 16PB
What would "top" mean in this situation. I see no numeric or obviously relative items in your explanation.
Dec 19 '07 #2
What would "top" mean in this situation. I see no numeric or obviously relative items in your explanation.
Hi There

Sorry wasn't completely clear with my post. each status will have a status date. I would like the "top" value per status date.

Many Thanks

Dan
Dec 19 '07 #3
NeoPa
32,556 Expert Mod 16PB
I shouldn't have to ask you to post the information required to even understand the question. Having gone to that trouble, I don't expect to have to point out again that the information provided is inadequate. I won't continue as I'm in danger of saying something I may later regret.
Dec 19 '07 #4
I shouldn't have to ask you to post the information required to even understand the question. Having gone to that trouble, I don't expect to have to point out again that the information provided is inadequate. I won't continue as I'm in danger of saying something I may later regret.
well thats a bit rude. so much for these forums being helpful.

its quite obvious that i was refering to the most recent .
Dec 19 '07 #5
I am not an expert, but we would still need more informations to help you.
I am not a flammer and I won't flame you since I have no reasons to do so anyway.

Regards
Dec 19 '07 #6
jaxjagfan
254 Expert 100+
Still not sure what you are looking for however:

Put together your query with the associated linking tables till you have columns you want.
Test it to make sure the data will be displayed.
Switch to SQL view and add TOP 1 to the select statement.
Expand|Select|Wrap|Line Numbers
  1. SELECT TOP 1 StoreID, StoreName, Status, StatusDate
  2. From "whatever your table names and joins are"
  3. Order by StatusDate
The TOP 1 predicate will only select the very first store selected in the query. If you have 25 stores then put TOP25. I don't like doing this due to number of stores varying over time.

Use same query and take out the TOP 1. Try using a Group By and select Max(StatusDate) and First(StatusID). This would return all rows for that row's "most recent status date".

It depends on what you want as results - your post is still vague.
Dec 19 '07 #7
NeoPa
32,556 Expert Mod 16PB
well thats a bit rude. so much for these forums being helpful.

its quite obvious that i was refering to the most recent .
You seem to have a difficulty understanding what is, and what is not good manners.
Bad manners is asking for help without bothering even to spend any effort on formulating a clear question (in fact it was not just unclear. It was fundamentally incorrect).
Compounding that by simply repeating what you'd already said when asked for clarification - and implying that I'm stupid for not understanding your sloppy post, is also bad manners (obviously).

Part of my job is to guide posters when they fail to observe the rules of this site (Posting Guidelines).
I believe I managed to do this simply stating facts that, indeed, needed to be stated. If you see that as rude then we clearly have very different ideas as to what constitutes good manners.

If you're unhappy with my response you have every right to refer this to another administrator to consider.

ADMIN.
Dec 20 '07 #8
Rabbit
12,516 Expert Mod 8TB
Perhaps I can clear up what's confusing about your question.

I would like to run a query which finds the "top" value per store id.
We don't know what value you're talking about here.

each status will have a status date. I would like the "top" value per status date
We were talking about "per store id" and all of a sudden we're talking about "per status date." Also, again you use the word value without qualifying what that is. By inference I assume you mean status. So it sounds as if you want the "top" status per status date. Even if this were correct, we don't know what your status variable holds. So by top are we talking about sorted alphabetically? Sorted numerically? Descending? Ascending?

its quite obvious that i was refering to the most recent .
Most recent? Are you talking about most recent status date as top? That's not what you said earlier, or even in your first post. From the prior post it would seem you want top status, but in this one it sounds like you want most recent status.

In each post your definition of "top" and "grouping variable" changes so you should be able to see why we're confused.

And that's not to mention that I think this older post is the same as this post. And in it you confused me and never responded to my last post.
Dec 20 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul Lamonby | last post by:
Hi, i want to create a unique serial number to my Db entries. I thought the best way would be to add the auto_increment primary key value to a string, then insert it into a table field...
1
by: Jake | last post by:
I have a deadlock situation, part of the problem looks like this; spid ecid dbid ObjId IndId Type Resource Mode Status ------ ------ ------ ----------- ------ ----...
1
by: Mad Scientist Jr | last post by:
I don't know how this is happening, but a dropdown control I have is resetting to the 2nd value on the list anytime a postback occurs. I have no initiation code outside of If Not (IsPostBack) ...
2
by: HH | last post by:
Hi, I have a dropdown list that is datafilled via a SQL table. The text part is always unique. (A list of countries) Each country is assigned one of three numbers. (This being the 'value' of...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
3
by: binder | last post by:
I am designing a new table with a few columns that may or may not have a value on each row that is inserted. What issues determine whether to allow a NULL value to be inserted for that column or...
9
by: Jae | last post by:
Hi I wonder how can I implement the STL map sorting by value. For example, I have a map m map<int, intm; m = 10; m = 5; m = 6;
2
by: pstachy | last post by:
Hi again! I have another issue. I would like the attribute of the tag <invoice> to be unique. Made the following schema but unfortunately it doesn't validate. Could someone please indicate what is...
10
by: Phil Latio | last post by:
I am inserting data into user table which contains 5 fields, sounds simple enough normally but 2 of the fields are designated as UNIQUE. If someone does enter a value which already exists, how do I...
0
by: cephal0n | last post by:
Hi All! I have two table tblHome1, contains all the unique PinNo and tblHome2 contains a duplicated PinNo and description. I put an automatic numbering (ProdID) and set it as my index. What I want...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.