Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Another SQL Server 2000 Query Conundrum
Message
From
24/07/2007 09:42:16
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Another SQL Server 2000 Query Conundrum
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01243142
Message ID:
01243142
Views:
69
1st Query (this pulls the correct records and works as it should):
SELECT * FROM table1 AS tw 
   INNER JOIN  
     (SELECT table2.inci_id FROM table2  
        WHERE  table2.inci_id = '07000244      ' 
        or table2.inci_id = '2007093878    ' 
        or table2.parent_id = '07000244      ' 
        or (LEN(table2.parent_id)>0 AND table2.parent_id = '2007093878    ')) qry1
   ON tw.inci_id = qry1.inci_id WHERE canccode='    ' ORDER BY tw.inci_id, tw.vehnum

Now I want to find all of the matching records in another table based on the value in the vehi_id field
in the qry1 result set. The vehi_id field will be in the result set qry1. It is also in table3 which has the records I want to pull.

My idea was basically:
SELECT * FROM table3 as vh
   INNER JOIN
      (insert 1st Query Above Here) qry2
   ON vh.vehi_id = qry2.vehi_id
However, it returns an error message that "column 'inci_id' was specified multiple times for tbl2" which I do not get since the 1st qry is the only one specifying inci_id and it works fine when run alone.

Here is the full query which I think should work:
SELECT * from table3 as vh
 inner join 
 (SELECT * FROM table1 AS tw 
    INNER JOIN  
     (SELECT table2.inci_id FROM table2  
        WHERE  table2.inci_id = '07000244      ' 
        or table2.inci_id = '2007093878    ' 
        or table2.parent_id = '07000244      ' 
        or (LEN(table2.parent_id)>0 AND table2.parent_id = '2007093878    ')) qry1
        ON tw.inci_id = qry1.inci_id WHERE canccode='    ') qry2 
     on vh.vehi_id = qry2.veh_id
Am I missing something obvious, AGAIN?
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Next
Reply
Map
View

Click here to load this message in the networking platform