Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select Conundrum
Message
 
 
To
27/07/2006 09:18:20
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01140649
Message ID:
01140659
Views:
20
This message has been marked as the solution to the initial question of the thread.
Tracy,

Try
select 
		t22.field3, t23.field3, t1.field1 
	from table1 t1
	JOIN table2 t22 ON t22.field1 = 'FKEY1' and t22.field2 = t1.field2
	JOIN table2 t23 ON t23.field1 = 'FKEY2' and t23.field2 = t1.field3
>I have two tables and I want to pull related records from table2 based on the values in table1. Instead of pulling the actual values in table1 field2 and field3 I want to pull their description from table2:
>
>
>table1 has:
>
>field1 field2 field3
>  id1   100    200
>  id2   101    310
>
>table2 has:
>
>field1    field2  field3
> FKEY1     100    Warehouse
> FKEY1     101    Boxes
> FKEY2     200    Storage
> FKEY2     310    Nicknacks
>
>
>The cursor result I want to achieve is:
>
>table2.field3, table2.field3, table1.field1
>
>I only want to return field1 from table1 and field3 from table2.
>
>The resultant cursor would be:
>
>Warehouse    Storage         id1
>Boxes        Nicknacks       id2
>
>
>This is manually achieved by the following:
>
>1. table1.field1 is the id for the record in table1 this should always be the last field returned
>2. the description for field2 in table1 is from table2.field3 records where table2.field1 value = 'FKEY1' and table2.field2 value = table1.field2
>3. the description for field3 in table1 is from table2.field3 records whose table2.field1 value = 'FKEY2' and table2.field2 value = table1.field3
>
>I want to:
>
>select * from table1 (I want all records from table1 but only field1)
>JOINED ON:
>select table2.field3 where table2.field1 = 'FKEY1' and table2.field2 = table1.field2
>AND JOINED ON:
>select table2.field3 where table2.field1 = 'FKEY2' and table2.field2 = table1.field3
>
>Am I making sense? For some reason I cannot wrap my head around this today.
>
>TIA,
>Tracy
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform