PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

SQL Statment?

Lets say your database is full of invoice line items and the invoice properties, so there for each line would look like

InvcNo Item             [Additonal Invc info]
366    Blah             [Additonal Invc info]
366    somthing         [Additonal Invc info]
366    not the same     [Additonal Invc info]
367    Whatever         [Additonal Invc info]
367    Blah             [Additonal Invc info]

Does anyone know to add to a SELECT to only i of each item by it InvcNo. So the query would ony return

InvcNo Item             [Additonal Invc info]
366    Blah             [Additonal Invc info]
367    Whatever         [Additonal Invc info]


I tried "SELECT DISTINCT * FROM InvcData" But it seemed to crash any ideas?
Damn it all! It seams that Distinct makes sure that all the data in the record is unique, So you cant use it to select all the data, and make it "DISTINCT" or unique by just one field. Any ideas?
Chris Edwards · 15 Nov 2001, 23:11 UTC
ok... don't really understand what you are trying to do.

you want it to return the first of each record #?

nevermind... i understand now :)

SELECT DISTINCT InvcNo, * FROM InvcData

selecting the distinct from * is probably where it's dying.. you can't tell it to eliminated duplicated entries in all the columns... just one.. so than we add a * later on...

tell me how that works.
You could do this too
Code:

SELECT DISTINCT ROW * FROM InvcData

Ever think about using common notation?  Like tblInvoiceData, where 'tbl' indicates it is a table, and fldMyField where 'fld' indicates a field.  It is pretty useful.
</ATTEMPT TO MAKE EVERYONE USE HUNGARIAN NOTATION>
No actually we use our own in house notation at the place i work, its called cci so therefore it would be CCIInvcData.
Chris Edwards · 16 Nov 2001, 17:32 UTC
so.... did it work ? :)
No it didnt it still selected all the rows, i just need to to select one of each row if the column is unique. so instead of getting all of the line items with the invcno 3666 i should only get 1 line item back with the invcno 3666, as with all the other line items.
man this is annoying. i know how to do it, i've done this kind of thing in college - removing duplicates from a database and stuff...

cant you use access or something and do it visually then copy the generated code?
Thanks paul, but i dont need the where statement and ive aready tried it :(.

I dont know if you people know what i mean though am i unclear?

Ok lets say there is one table with 800 records (rows) each record contains 5 fields (columns) one of the fields is lets say item, the thing is there can be 5 records that have duplicate item fields lets say the item is soap, then we have ten of the item shampoo, and so on. I want to return a recordset that will contain only 1 soap and 1 shampoo record but has all ot the other info from the other fields besides item. I have been looking through books to get the answer but i cant find it the examples in all books and msdn return just that one item field.  
yeah, i know...

SELECT DISTINCT item
FROM tablename;

...will get you just the item column, but i'm not sure about the others. i'll edit this post in a minute, i think i might be able to find it.
SELECT DISTINCT InvcNo, Item, [Additonal Invc info]
FROM InvcData;

nah, thats rubbish, but i'll post it anyway because i'm bored waiting for my vid to download.

*voices in pauls head*
library girl!
library giiirrrll!!!

what? huh?!? ARRRRRRGGGGGGH!!!!!!

*drools*
Hmm i saw your modifaction of your post with that access thing. I dont know how to use access acually, i only use sql and vb. Maybe you could do it in access with a some made up data and show me the code it generates?
i have access 97 - doesnt work at the mo - i have access 2000 - not installed - cant be bothered right now, can you wait until tomorrow?

unless i suddenly can be bothered, in which case i'll do it soon.
O thats cool, if you get aroud to it let me know. For now im just gonna do this all with vb code althought thats a horribly slow ass way.
just a guess but try DISTINCTROW instead
Ummm... I SAID USE DISTINCTROW FIRST!
No i cant do DISTINCTROW, it only work with joined tables, this is just one table. Anyways i have pretty much fixed this whole problem by telling SQL to fuck off and writing a function in vb to handle it.