MySQL Query Containing Multiple Queries

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
portem1
Forum Newbie
Posts: 3
Joined: Tue Jan 18, 2011 2:50 am

MySQL Query Containing Multiple Queries

Post by portem1 »

I have a database that holds basic "products", "users", and "sales" information for a shop.
I am having a few problems with a MySQL query that will retrieve the following information from the appropriate tables.
The Purchasers "Username".
The "Name" of the purchased item.
The "Price" of the purchased item.
The "time" the item was purchased.
If any items have been purchased multiple times by a purchaser, I need to only show the latest one. Can this be done?

The structure of the tables can be seen below.

Table "Products":
product_id - Used as a unique identifier.
name - The name of the product.
price - The price of the product.

Table "Users":
user_id - Used as a unique identifier.
username - The username of the purchaser.

Table "Sales":
sale_id - Used as a unique identifier.
product_id - The unique identifier of the purchased product.
user_id - The unique identifier of the purchaser.
time - The date and time the sale took place.
Can anyone help?
Any Help is Much Appreciated!
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: MySQL Query Containing Multiple Queries

Post by mikosiko »

Can anyone help?
with what exactly you need help?...

post your code
Peter Kelly
Forum Contributor
Posts: 143
Joined: Fri Jan 14, 2011 5:33 pm
Location: England
Contact:

Re: MySQL Query Containing Multiple Queries

Post by Peter Kelly »

Just sort it by ID then limit it to just 1 row. So on the end of the SQL query you would add LIMIT 0,1
portem1
Forum Newbie
Posts: 3
Joined: Tue Jan 18, 2011 2:50 am

Re: MySQL Query Containing Multiple Queries

Post by portem1 »

Peter Kelly wrote:Just sort it by ID then limit it to just 1 row. So on the end of the SQL query you would add LIMIT 0,1
Good idea. Thanks :)
Post Reply