Hello,
I have a query like this: - SELECT jos_vm_orders.user_id, jos_vm_orders.cdate, sum( order_total ) AS total, count( jos_vm_orders.order_id ) AS ordercount, jos_vm_user_info.first_name, jos_vm_user_info.last_name, jos_vm_user_info.phone_1, jos_vm_user_info.user_email, jos_vm_user_info.city
-
FROM jos_vm_orders
-
LEFT JOIN jos_vm_user_info ON jos_vm_orders.user_id = jos_vm_user_info.user_id
-
WHERE jos_vm_orders.order_status = 'C'
-
GROUP BY jos_vm_orders.user_id
-
LIMIT 0 , 30
When there is more than one order for same user_id the script selects the first order cdate, but I would like to select the last one. Any ideas?
2 2383
This actually an illegal query except MySQL uses an algorithm to 'guess' the fields you require where you haven't used an aggregate or a GROUP BY.
So jos_vm_orders.cdate, jos_vm_user_info.first_name, jos_vm_user_info.last_name, jos_vm_user_info.phone_1, jos_vm_user_info.user_email, jos_vm_user_info.city are all chosen for you.
To specify the last date you could try
MAX() or use HAVING.
Well all other information for one user_id ir the same, but the cdate differs. Thank you very much for MAX(), this solved my probled because date is stored in timestamp format.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: mr_burns |
last post by:
hi,
i have two tables that i am joining using the following sql:
SELECT * FROM clients, programmes WHERE clients.client_id =
programmes.client_id AND programmes.client_id = 12
if both...
|
by: Toby |
last post by:
Dear All,
I wounder whether some of the experts out there might be able to help
me with a problem I'm having. I do not know whether this is possible or
not...
I have a large table of stock...
|
by: eric404 |
last post by:
(I don't post here often, so in case I'm violating long-standing taboos
of this newsgroup, I apologize in advance for calling a relation a
table, using nulls, and other ignorant, destructive, and...
|
by: Palle Girgensohn |
last post by:
Hi!
A performance question:
I have some tables:
Tabell "public.person"
Kolumn | Typ | Modifierare
------------------+--------------------------+---------------...
|
by: PC |
last post by:
Hi,
I have used the DLast("!","")function
to find and display the last entry in a table. How would I go about
displaying the last record in a table that is not Null?
Thanks in advance
...pc
|
by: David Messner |
last post by:
Ok I know this is simple but the statement eludes me...
I have a date field where I want the default value on the data entry form's
date field to be the last date entered. I figure I can do this...
|
by: John Veldthuis |
last post by:
My code works perfectly 100% when adding items to my ArrayList and updating the listbox.
Works perfectly when deleting an item in the ArrayList when it is not the last entry but if it is
the last...
|
by: Sakakini |
last post by:
How can I append last entry from one table to another table???
|
by: Wernerh |
last post by:
Hi, I have created a log in a listbox to show users everytime someone has logged on. Is there a form load function that will scroll down the listbox to the last entry each time the form is loaded??
...
|
by: karuppiah |
last post by:
Hi All,
i need query,how to select last 3 month ,last 3wek,last 3 days , this last 3 month and 3 week should be friday, using sysdate from dual table, there is no exsting table, pls any one help...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
| |