Query SQL get two values differents from the same columns

Hi, I have 2 different values in the same column and two different values in other column

Query 1

ins   name     value
1     Test      12345
1     TestV1   12/10/2014
8     Test       85435
8     TestV1   11/11/2005
9     Test       42232
9     TestV1   19/10/2000
6     Test      54321
6     TestV1   11/05/2013

And i have other sql query with the result

Query 2

values
12345
54321

I want to match all the results of the last field of the first query
I want to get:

12345  12/10/2014
54321  11/05/2013

Thanks in advance

Post database type(i.e. oracle, db2, mySql, etc.), table def, table data, sql you are running.

Database MS sql 2005 both data tables are query results I need some like JOIN inner,left or right.

Post your table definitions(i.e columns) for your two tables so we can assist you in learning how to join the two tables to produce the output you desire.

Ok.

select a.value, (select value from TABLE_NAME b
    where b.ins = a.ins and b.name = 'TestV1')
  from TABLE_NAME a
  where name = 'Test';
SQL>
SQL> --
SQL> select * from t1;
 
       INS NAME       VALUE
---------- ---------- ----------
         1 Test       12345
         1 TestV1     12/10/2014
         8 Test       85435
         8 TestV1     11/11/2005
         9 Test       42232
         9 TestV1     19/10/2000
         6 Test       54321
         6 TestV1     11/05/2013
 
8 rows selected.
 
SQL>
SQL> --
SQL> select * from t2;
 
VALUE
----------
12345
54321
 
2 rows selected.
 
SQL>
SQL> -- Method 1
SQL> select x.value, z.value
  2    from t1 x
  3         join t2 y on (y.value = x.value)
  4         join t1 z on (z.ins = x.ins and z.name = 'TestV1')
  5  ;
 
VALUE      VALUE
---------- ----------
12345      12/10/2014
54321      11/05/2013
 
2 rows selected.
 
SQL>
SQL> -- Method 2
SQL> select x.value,
  2         y.testv1_value
  3    from t2 x
  4         join (
  5                   select ins,
  6                          max(case when name = 'Test' then value end) as test_value,
  7                          max(case when name = 'TestV1' then value end) as testv1_value
  8                     from t1
  9                    group by ins
 10              ) y
 11         on (x.value = y.test_value)
 12  ;
 
VALUE      TESTV1_VAL
---------- ----------
12345      12/10/2014
54321      11/05/2013
 
2 rows selected.
 
SQL>
SQL>