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 January 14th, 2013, 10:55 AM
rseigel rseigel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 rseigel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 48 sec
Reputation Power: 0
Exclamation SELECT issues

I have two SELECTS that grab the info that I need to create a csv file.

$result = mysql_query("SELECT product_attribute.supplier_reference, product.price, product.wholesale_price
FROM product_attribute, product
WHERE product.id_product = product_attribute.id_product");

$result = mysql_query("SELECT product_supplier.product_supplier_reference, product.price, product.wholesale_price
FROM product_supplier, product
WHERE product.id_product = product_supplier.id_product");

Basically, I want the first one to run complete. It's fine as is.

For the second one I want to eliminate any records where product.id_product was present in the first SELECT and add the rest to the csv.

Any ideas?

TIA!

Ron

Also.....


An even more perfect situation would be if I could combine the two SELECTS into one.

Reply With Quote
  #2  
Old January 14th, 2013, 11:06 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,361 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 5 h 30 m 59 sec
Reputation Power: 4140
here ya go, one query --
Code:
SELECT product_attribute.supplier_reference
     , product.price
     , product.wholesale_price
  FROM product_attribute
INNER
  JOIN product
    ON product.id_product = product_attribute.id_product
UNION -- removes duplicates    
SELECT product_supplier.product_supplier_reference
     , product.price
     , product.wholesale_price
  FROM product_supplier
INNER
  JOIN product
    ON product.id_product = product_supplier.id_product
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old January 14th, 2013, 11:59 AM
rseigel rseigel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 rseigel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 48 sec
Reputation Power: 0
YOU ROCK!

Work perfectly and I learned something new.

Thanks a million.
Comments on this post
cafelatte agrees: Of course, we ALREADY knew that Rudy rocks :-)

Reply With Quote
  #4  
Old January 14th, 2013, 12:37 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,361 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 5 h 30 m 59 sec
Reputation Power: 4140
Quote:
Originally Posted by rseigel
... and I learned something new.
hopefully, this new thing you learned was how to write explicit JOIN syntax rather than the deprecated comma list style with the join condition in the WHERE clause

but i'm curious why you bothered to also post this question on dbforums, ~after~ i posted my solution here


Reply With Quote
  #5  
Old January 14th, 2013, 12:39 PM
rseigel rseigel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 rseigel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 48 sec
Reputation Power: 0
Quote:
Originally Posted by r937
hopefully, this new thing you learned was how to write explicit JOIN syntax rather than the deprecated comma list style with the join condition in the WHERE clause

but i'm curious why you bothered to also post this question on dbforums, ~after~ i posted my solution



Point taken.

Reply With Quote
  #6  
Old January 14th, 2013, 12:40 PM
rseigel rseigel is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 6 rseigel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 53 m 48 sec
Reputation Power: 0
I actually posted them both at the same time - give or take.

Reply With Quote
  #7  
Old January 14th, 2013, 01:41 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,361 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 5 h 30 m 59 sec
Reputation Power: 4140
Quote:
Originally Posted by rseigel
I actually posted them both at the same time - give or take.
if i notice it sooner (which i did not, this time), i will usually post a link from one forum into the other, even if no replies have been made yet

i hate seeing people waste their time, as actually happened in this case, re-creating a solution that's already been posted, or worse, barking up the wrong tree because further clarification was elicited in the other forum that they aren't aware of

the only circumstance under which i find cross-posting acceptable is when a goodly amount of time has elapsed on one forum with no replies, then it's okay to post the same question into a different forum

not everyone agrees with this sentiment, though


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > SELECT issues

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