Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which record in query came from this table?
Message
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01398723
Message ID:
01398767
Views:
60
>>>>>>All records are coming from both tables. That's how JOIN works.
>>>>>>
>>>>>
>>>>>Even I knew that <g>. But for every record in Table1 the query pulls 1 or more records from Table2. So I was hoping to be able to find the one record that was the "primary" (I know this is not the right word but you know what I mean) record from Table1.
>>>>
>>>>Put pk into the result!
>>>>
>>>>Every pk of the table1 is a table1's record.
>>>>Every pk of the table2 is a table2's record.
>>>
>>>I tried this. But the resulting query has both PKs. So just putting PKs in the resulting query does not seem to help. Unless, as Michael suggested, I order on the PK of Table2 and then the row with the smallest PK value from Table2 is the record from Table 1. Thank you for your suggestion.
>>
>>Assuming
>>
>>Table1
>>PK  NameField
>>1      Name1
>>2     Name2
>>
>>Table2
>>
>>PK FK NameField
>>1    1   Test1
>>2    1  Test2
>>3    2  Test3
>>
>>You should get as a result of the join
>>
>>1  Name1  1 1 Test1 - In the first two records first two columns repeat the information
>>1  Name1  2 1 Test2
>>2  Name2  3 2 Test3
>>
>>
>
>What columns in your resulting query the column 3 and column 4; the one that you say will repeat the information?

select * from Table1 inner JOIN Table2 on Table1.PK = Table2.FK

This would result in

Table1.PK, Table1.NameField, Table2.PK, Table2.FK, Table2.NameField

In the result 2 first columns would have repeated info and then column4 in case of 1 to many


T1 T1 T2 T2 T2
PK NameField PK FK NameField
R R U R U

Where R stands for repeated and U for unique

(I can not make it show correctly, you need to press answer button to see what I meant)
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform