Good evening good people on these forums!
I'm sure there are more people asking this question, I however don't have a clue as to how to search for it..
so here goes:
I have a Table, which I'll call 'Table' for now.
This table contains the following fields (note: this is an exerpt, I only need these 4 fields)
Table.ID, Table.BRKNo, Table.PalletNo, Table.Tab, Table.SN, Table.Asset
and these 4 fields contain the following 4 values:
[ID][BRKNo][PalletNo][Tab][SN][Asset]
[11][BRK01][Pallet01][Tested][123][As322]
[12][BRK02][Pallet01][Tested][623][As1242]
[13][BRK02][Pallet01][UnTested][234233][As1212]
...
[27][BRK02][Pallet02][Waste][23425][As212]
...
[39][BRK03][Pallet01][Tested][123][As112]
and so on and so on.
Since this old database has been a project from an ex colleague of mine, I'm doing a bit of normalization, and decided to cut off the Tab field from this table, and stick it into another table:
TableTabs
which will contain the following fields:
TableTabs.ID, TableTabs.BRKNo, TableTabs.PalletNo, TableTabs.Tab
however, since the old database was already in use and got kinda screwed up due to some bad coding (see ID 12 and 13 in the prev. example)
This is what happened:
A client would insert a pallet into a BRK (which is just code for a project) and assigns a tab to that (Tested, Not Tested, Waste). However, every pallet can only have one sort of Tab. Meaning that The record with ID 12 is correct, and the ID #13 is a bad one (got kinda screwed up with Tab.Defaultvalue on the forms).
So, here's what I'm trying to do:
I'm creating a select query that selects the BRKNo and PalletNo and Tab values as distinct. This is not the problem, this gives me:
[BRK01][Pallet01][Tested]
[BRK02][Pallet01][Tested]
[BRK02][Pallet01][UnTested]
and so on.
However, for my new table population, I need only the FIRST record on that BRK - Pallet combination (so that I get the following result in my table
[BRK01][Pallet01][Tested]
[BRK02][Pallet01][Tested]
[BRK02][Pallet02][Waste]
and so on
for this, I need the ID. however.. selecting the ID with the rest of the query just gives me all the other results as well.
is there a way for me to select the combination of BRKNo, PalletNo, Tab and the FIRST value of ID occuring in this combination?
----
By the way: Yes, I am sure that the FIRST ID occuring in this combination is the correct Tab to insert into the new table. Since this is created when the user creates the actual pallet in the database.
Untill now i've only found out the following code:
this gives me exactly what I want.. except for the duplicate values on (in this example) BRK02, Pallet01.Code:SELECT BRKNo, PalletNo, Tab FROM Table GROUP BY BRKNo, PalletNo, tabblad
Thanks in advance,
And don't mind to ask me for more explaination.. I know what I want, yet it's a bit hard to explain to people that do not
ps. I only need to run this query once.. but it has to be done since there are like 50.000+ unique BRK's and Pallet combinations.. and I do not like to do that all by hand ^^