|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|
#2
|
|||||
|
|||||
|
RE: MySQL Query Syntax
Try this:
php Code:
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
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 |
|
#5
|
|||
|
|||
|
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. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > MySQL Query Syntax |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|