Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-12-2011, 12:09 AM   PM User | #1
vjoho
New Coder

 
Join Date: Apr 2011
Posts: 11
Thanks: 3
Thanked 0 Times in 0 Posts
vjoho is an unknown quantity at this point
SQL INNER JOIN Issue

I'm trying to set up a query that selects the most recent item uploaded from the 4 subcategories (Dresses, Skirts, Shorts, Coats) of the category 'Apparel'. The problem is that the coding below is not limiting the result of 1 of each subcategory and I don't know how to fix that. Below is the code I set up and here's a link to the page I'm having issues with:

http://www.tarimah.com/temp/Apparel.php

$query1 = mysql_query("SELECT *
FROM products
INNER JOIN
(SELECT subcategory as scat, max(date_added) as date
FROM products WHERE category = 'Apparel' group by subcategory) as prod
on products.subcategory = prod.scat and products.date_added = prod.date");

Thanks for reading my post!
vjoho is offline   Reply With Quote
Old 09-12-2011, 03:53 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
You can adapt the solution here: http://www.artfulsoftware.com/infotree/queries.php#101
it finds the lowest price per group. you'll need to modify it so it finds the most recent date per group.
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:33 AM.


Advertisement
Log in to turn off these ads.