0

I'm trying to make two select queries so that second selection have to based on first. I give first table name "t1" and try to make second selection based on first but finally i get database error.

SQL

SELECT startpoli_i ,
       finalpoli_i ,
       prosfora ,
       comments_pro ,
       accepted ,
       onoma01 ,
       epitheto01 ,
       email01 ,
       tilefono01 ,         
       weight1 ,
       depdate1 ,
       specialservices1 ,
       comments1 ,
       username01
FROM   (offers ,registration1 ,customer)  t1
WHERE  (
              offers.string_uniq regexp concat( :str)
       AND    registration1.username01 = offers.user_i
       AND    customer.startpoli1 = offers.startpoli_i
       AND    customer.finalpoli1 = offers.finalpoli_i )
UNION
SELECT startpoli_i ,
       finalpoli_i ,
       prosfora ,
       comments_pro ,
       accepted ,
       onoma01 ,
       epitheto01 ,
       email01 ,
       tilefono01 ,          
       weight1 ,
       depdate1 ,
       specialservices1 ,
       comments1 ,
       username01
FROM   offers ,
       registration1 ,
       customer
WHERE  offers.startpoli_i = t1.startpoli_i
AND    offers.finalpoli_i = t1.finalpoli_i          

I am pretty sure that error has to do with how i use table name t1. Any suggestion;

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194
telis
  • 35
  • 4
  • 2
    What's the error? Do the queries work individually? What do you mean 'based on first query?' union will merge the results. – William_Wilson Oct 07 '15 at 16:18
  • I get no results. First query works individually. With 'based on first query' i mean that i try to name first selection as "t1" and get second table with "offers.startpoli_i = t1.startpoli_i AND offers.finalpoli_i = t1.finalpoli_i " statements where ti is involved – telis Oct 07 '15 at 16:22
  • I am fairly certain you cannot reference one part of a UNION in another part of it. I am not even sure it could make logical sense to do so. – Uueerdo Oct 07 '15 at 16:29

1 Answers1

0

SELECT startpoli_i , finalpoli_i , prosfora , comments_pro , accepted , onoma01 , epitheto01 , email01 , tilefono01 ,
weight1 , depdate1 , specialservices1 , comments1 , username01 FROM offers , registration1 , customer,(SELECT startpoli_i , finalpoli_i , prosfora , comments_pro , accepted , onoma01 , epitheto01 , email01 , tilefono01 ,
weight1 , depdate1 , specialservices1 , comments1 , username01 FROM (offers ,registration1 ,customer) t1 WHERE ( offers.string_uniq regexp concat( :str) AND registration1.username01 = offers.user_i AND customer.startpoli1 = offers.startpoli_i AND customer.finalpoli1 = offers.finalpoli_i )) WHERE offers.startpoli_i = t1.startpoli_i AND offers.finalpoli_i = t1.finalpoli_i ;

rks
  • 9
  • 4