mysql - Left/Right Join with reference to another table -
I'm trying to reach three tables to do something like this:
< Code> + - ----- + ------ + ------ + | Items | PCS | CSS | + ------ + ------ + ------ + | 10 99 | 2 | 11 | | 10 9 8. 2 | 2 | | 10 9 7. 2 | 1 | | 10 9 6. Faucet Faucet | 10 9 5. Faucet Faucet | 10 9 4. Faucet Faucet | 10 9 3. Faucet Faucet | 10 9 2. Faucet Faucet + ------ + ------ + ------ +But, I get all this:
+ ------ + ------ + ------ + | Items | PCS | CSS | + ------ + ------ + ------ + | 10 99 | 2 | 11 | | 10 9 8. 2 | 2 | | 10 9 7. 2 | 1 | + ------ + ------ + ------ +
// I'm confused with my query, so here's a breakdown Instead of what I am trying to do:
SET2 WHERE MO = MONTH (SYSDATE ()) and YR = YEAR (SYSDATE ()) // Select the code and then: SELECT ITEM , Select items from SET3 WHERE S3.CODE = S2.CODE // again: SET1 WHERE S1 by PCS, CSS. ITEM = S3.ITEM
My table
SET1
+ ------ + | Items | + ------ + | 10 99 | | 10 9 8. | 10 9 7. | 10 9 6. | 10 9 5. | 10 9 4. | 10 9 3. | 10 9 2. + ------ +
SET2
+ ------ + ----- + ------ + | Yar | MO | Code | + ------ + ----- + ------ + | 2013 | 1 | 1 | | 2013 | 2 | 2 | + ------ + ----- + ------ +
SET3
+ ------ + ----- + ------ + ------ + | PCS | CSS | Code | Items | + ------ + ----- + ------ + ------ + | 2 | 11 | 1 | 10 99 | | 2 | 2 | 1 | 10 9 8. | 2 | 1 | 1 | 10 9 7. + ------ + ----- + ------ + ------ +
You must use left join to work:
Select SELECT1. Connect the CSS, SET3 on SET3, excluding ITEM, PCS, SET1. ITEM = SET1.ITEM SET2.CODE = SET3 .CODE and SET2.MO = MONTH (SYSDATE ()) and SET2.YR = YEAR (SYSDATE ())
Comments
Post a Comment