Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase 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 Codewalkers Forums Sponsor:
  #1  
Old November 11th, 2003, 02:05 PM
NESA NESA is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Portland, ME USA
Posts: 10 NESA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
MySQL Query Syntax

I am trying to get all of the fields (including ColorNumber) from tPC where the tPC.ItemNumber == $ItemVar and get all of the records from tSC where tPC.ColorNumber == tSC.ColorNumber AND tSC.StoreNumber == $StoreVar

Reply With Quote
  #2  
Old November 11th, 2003, 04:05 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: MySQL Query Syntax

Try this:
php Code:
Original - php Code
  1.  
  2. $result = mysql_query("SELECT * FROM tPC LEFT JOIN tSC ON tPC.ColorNumber=tSC.ColorNumber WHERE tPC.ItemNumber='$ItemVar' AND tSC.StoreNumber='$StoreVar'");


Reply With Quote
  #3  
Old November 11th, 2003, 04:32 PM
NESA NESA is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Portland, ME USA
Posts: 10 NESA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: MySQL Query Syntax

w/ the above Query I do not get any records when tPC.ColorNumber existed, but not a corresponding tSC.ColorNumber. I orginally tried this query: "SELECT tPC.*, tSC.* FROM tPC LEFT JOIN tSC USING (ColorNumber) WHERE tPC.ItemNumber = '$ItemVar'" this almost worked (although it did not exclude items where tSC != '$storeVar') but when a record from tPC did not have a corresponding record in tSC fields that overlapped (like ColorNumber) were returned as NULL. Fields that were just in tPC returned their values and fields just in tSC returned NULL as expected. I need all of the ColorNumber values from tPC plus any values from corresponding records in tSC if those tSC records have the correct StoreNumber. I appreciate any help.

Reply With Quote
  #4  
Old November 11th, 2003, 08:08 PM
honcho's Avatar
honcho honcho is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Cape Cod
Posts: 1,347 honcho User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 52 m 2 sec
Reputation Power: 3
RE: MySQL Query Syntax

You're going to need two queries then:
Code:
SELECT * FROM tPC WHERE tPC.ItemNumber='$ItemVar'

and
Code:
SELECT tSC.* FROM tSC LEFT JOIN tPC ON tPC.ColorNumber=tSC.ColorNumber WHERE tPC.ItemNumber='$ItemVar' AND tSC.StoreNumber='$StoreVar


Reply With Quote
  #5  
Old November 13th, 2003, 01:14 PM
NESA NESA is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Portland, ME USA
Posts: 10 NESA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: MySQL Query Syntax

I managed to get it right, all in one query with the help of -Vertigo- (thanks) it goes as follows:
SELECT tPC.*, tSC.*
FROM ProductColors tPC
LEFT JOIN StoreColors tSC
ON (tSC.ColorNumber = tPC.ColorNumber
AND tSC.ItemNumber = tPC.ItemNumber
AND tSC.StoreNumber = '$storeVAR')
WHERE tPC.ItemNumber = '$itemVAR';
I did not know you could put conditions just on the joined data. I hope this helps someone else too.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > MySQL Query Syntax


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT