Hello,
I have following table:
product| ordered_by | date
n1 | A | 2006-01-01
n1 | A | 2006-02-01
n1 | D | 2006-03-01
n1 | B | 2006-05-01
n2 | B | 2006-01-01
n2 | C | 2006-04-01
....
As a result I only want one set per product with the latest "ordered_by ".
In this example:
n1, B and
n2, C
So far I solved it within the executing program but I was wondering if there
is an efficient query to do the same.
Thanks,
James 5 4643
James Scott wrote: As a result I only want one set per product with the latest "ordered_by ". In this example: n1, B and n2, C
SELECT t1.*
FROM tablename t1
LEFT OUTER JOIN tablename t2 ON t1.product = t2.product AND t1.`date` <
t2.`date`
WHERE t2.`date` IS NULL
In other words, "show me the row where there is no other row with the
same product and a greater date."
Regards,
Bill K.
or...
select product,order_b y,max(date) from tablea group by
product,order_b y;
or...
select product,order_b y,max(date) from tablea group by
product,order_b y;
<on*******@firs tdbasource.com> wrote in message
news:11******** *************@j 55g2000cwa.goog legroups.com... or...
select product,order_b y,max(date) from tablea group by product,order_b y;
This won't work. read the OPs requirements.
Rich
"James Scott" <js************ @nospmahoo.com> wrote in message
news:IM******** *********@twist er.nyroc.rr.com ... Hello,
I have following table: product| ordered_by | date n1 | A | 2006-01-01 n1 | A | 2006-02-01 n1 | D | 2006-03-01 n1 | B | 2006-05-01 n2 | B | 2006-01-01 n2 | C | 2006-04-01 ...
As a result I only want one set per product with the latest "ordered_by ". In this example: n1, B and n2, C
So far I solved it within the executing program but I was wondering if
there is an efficient query to do the same.
Thanks, James
If you have subqueries, this will do it:
select product
,orderedby
from [order] as o1
where orderdate = (
select max(orderdate)
from [order] as o2
where o2.product = o1.product)
Rich This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kali K E |
last post by:
Hi,
I could not understand how I can do the following things in Python.
Please help me.
1. First I have to find the current directory from where the script is
invoked.
2. Next I have to form a directory structure there. If the current
directory in step 1 is /home/mylogin, then from there I have to build
a directory structure like
/home/mylogin/result
|
by: mike420 |
last post by:
In the context of LATEX, some Pythonista asked what the big
successes of Lisp were. I think there were at least three *big*
successes.
a. orbitz.com web site uses Lisp for algorithms, etc.
b. Yahoo store was originally written in Lisp.
c. Emacs
The issues with these will probably come up, so I might as well
mention them myself (which will also make this a more balanced
|
by: Franz Steinhaeusler |
last post by:
Hello NG,
I want to retrieve the members of a class
with a baseclass.
But the problem is, how to get the non derived
members.
class a:
def who(self):
print "who"
|
by: Kenneth Keeley |
last post by:
Hi,
I am looking for a sample of how to get the password last set for a user in
active directory in a format that we can read. I am using ASP.Net and C# I
have got as far as get the value. but I would like it as a normal date time
value. or at least display it as a string. if I use the code below the
response I get is "The password was last set :System.__ComObject" How do I
get this to a norma date format.
Thanks
|
by: henrycortezwu |
last post by:
Hi All,
I'm trying to get the "groups" of a user that belongs to a domain by
just passing the user's userID & domain. Is this possible?
What I tried, and is working is the ff code ( i can get both local &
domain groups), but in Windows Application.
When I tried converting it to ASP.NET, it only gets the local
groups.
| |
by: Chuck Faranda |
last post by:
I'm trying to debug my first C program (firmware for PIC MCU). The problem
is getting serial data back from my device. My get commands have to be sent
twice for the PIC to respond properly with the needed data. Any ideas?
Here's the code in question, see any reason why a command would not trigger
the 'kbhit' the first time a serial command is sent?: Thanks!
Chuck
****************************************************
while(1) //...
|
by: DavidPr |
last post by:
I'm getting - parse error, unexpected T_LNUMBER - error messages referring to the last "if" lines of this code.
What I'm trying to do is check the database and if this user's article row isn't empty AND the article that's in there isn't older than 90 days then execute the "if" clause. I've tried it two different ways and neither of them work. The trouble must be with this since it is in both ways that I've tried:
$posted > SUBDATE(NOW(),...
|
by: Alireza355 |
last post by:
I have two tables:
table1:
number explanation
10 something here
11 something here
12 something here
13 something here
14 something here
|
by: Sundhas |
last post by:
I made a Webservice Operation whose return type is STRING Following is the code
@WebMethod(operationName = "authorize") public String authorize(@WebParam(name = "Username") String Username)
{
CAuthorization CA = new CAuthorization();
String Result= null;
try {
Result = CA.CheckAuthorization(Username);
} catch (SQLException ex) {
Logger.getLogger(WS_Authentication.class.getName()).log(Level.SEVERE, null, ex);
|
by: twomcfly |
last post by:
Hi
I have a SQL Server 2005 database with a list of results for a variety of people over time. i would like to be able to look at any row and from that row know the last 3 results for that person
the columns are like this
date ----- person ----- result
i would like to be able to add in columns which would show
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |