Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQL Select question
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00794895
Message ID:
00794947
Vues:
14
You can use UNION clause in your select, e.g. first part would select your data and second would be a UNION to Parts only (no need to do joins).

Check out difference between UNION and UNION ALL in Help.

>I think I should get the Stupidity award <g>. In my SQL select there is a WHERE clause (which of course I didn't pay attention to <g>) that specifies the range of Receiving dates.
>
>Therefore, the SQL select should be as follows:
>
>select PARTS.PART_NO, sum( PARTS_RECEIVED.QTY ) as SUM_QTY from PARTS ;
>left join PO_PARTS on PARTS.PART_NO = PO_PARTS.PART_NO ;
>left join PARTS_RECEIVED on PO_PARTS.POPART_PK = PARTS_RECEIVED.POPART_PK ;
>where PARTS_RECEIVED.DATE_REC between ("this date" and "that date")
>
>
>Now that I know why it does not work, I still need help. Is it possibel to STILL have in the resulting query all records from PARTS? That is, I want the SUM_QTY for those parts which are not within Receiving Date Range to be set to 0.00 yet still included in the query.
>
>Is it possible?
>
>>No, I don't see anything wrong. What VFP version are you using, 6? Can you zip up small subset of your data and email to me so I can run some tests?
>>
>>>Sergey,
>>>I do have the GROUP BY in my code, I just missed it here in UT message.
>>>Do you see anything else that might be wrong with my code?
>>>
>>>>Hi Dmitry,
>>>>
>>>>Your select is missing
GROUP BY PARTS.PART_NO
>>>>
>>>>>I am having another problem, which probably stems from my misunderstanding of SQL Select.
>>>>>
>>>>>Three tables:
>>>>>
>>>>>Table 1: PARTS
>>>>>Fields: PART_NO, etc.
>>>>>
>>>>>Table 2: PO_PARTS (purchased parts)
>>>>>Fields: PART_NO, POPART_PK, etc.
>>>>>
>>>>>Table 3: PARTS_RECEIVED
>>>>>Fields: POPART_PK, DATE_REC, QTY, etc.
>>>>>
>>>>>When I have the following query:
>>>>>
>>>>>
>>>>>select PARTS.PART_NO, sum( PARTS_RECEIVED.QTY ) as SUM_QTY from PARTS ;
>>>>>left join PO_PARTS on PARTS.PART_NO = PO_PARTS.PART_NO ;
>>>>>left join PARTS_RECEIVED on PO_PARTS.POPART_PK = PARTS_RECEIVED.POPART_PK
>>>>>
>>>>>
>>>>>I get only those records from PARTS that have entries in PO_PARTS. I thought this SQL Select (because it is left join) would have all records from PARTS table.
>>>>>
>>>>>What am I missing?
>>>>>
>>>>>TIA.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform