MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 1st, 2013, 04:25 AM
qwertyjjj qwertyjjj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2010
Posts: 75 qwertyjjj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 7 m 39 sec
Reputation Power: 4
Join on latest row only

I am trying to join on a row from the wp_comments sta table.
However this is a status table and contains many rows for each order.
I only want to check if the comments on the latest row = changed form pending to processing and if so, then I want to bring back a record for the wp_posts ord table.
If the latest row in wp_comments sta = any other text, then I do not want to bring the record back.
Any ideas how I can do this? The current SQL brings back everything

SELECT*
FROM wp_posts ord
INNERJOIN wp_comments sta ON ord.ID = sta.comment_post_ID
WHERE ord.post_type LIKE'shop_order'
AND sta.comment_content LIKE'%changed from pending to processing%'
LIMIT 0 , 30

Reply With Quote
  #2  
Old February 1st, 2013, 09:27 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,373 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 6 h 54 m 33 sec
Reputation Power: 4140
Code:
SELECT somthing
     , anything
     , just_not_the_dreaded_evil_seclect_star 
  FROM wp_posts SA ord
INNER
  JOIN ( SELECT comment_post_ID
              , MAX(comment_post_datetime) AS latest
           FROM wp_comments
         GROUP
             BY comment_post_ID ) AS last
    ON last.comment_post_ID = ord.id
INNER
  JOIN wp_comments AS sta 
    ON sta.comment_post_ID = last.comment_post_ID
   AND sta.comment_post_datetime = last.latest
   AND sta.comment_content LIKE '%changed from pending to processing%' 
 WHERE ord.post_type = 'shop_order'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Join on latest row only

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap