-7

I need to get the data according this filter:

The result need to be all content that contain 1 on column2 and column22 from table2. In this case

Table1 = column2 = 1 Table2 = column22 = 1

Table1 = column1, column2, column3
            1       1       2
            2       1       2
            3       1       3
            4       3       3

Table2 = column11, column22, column33
            1           1       0
            2           0       0
            3           0       0
            4           0       0


SELECT * FROM 'Table1' WHERE 'colum2' = 1 AND SELECT * FROM 'Table2' WHERE 'column22'= 1;

Any help is appreciated.

Dario
  • 704
  • 2
  • 21
  • 40

2 Answers2

1

If you just want to return the rows from each table that match, then you can use a UNION ALL:

SELECT * 
FROM Table1 
WHERE column2 = 1 
union all
SELECT * 
FROM Table2 
WHERE column22= 1;

See SQL Fiddle with Demo

If you want to return the rows that match both criteria, then possibly you want to JOIN the tables:

SELECT * 
FROM Table1 t1
INNER JOIN Table2 t2
  on t1.column1 = t2.column11
where t1.column2 = 1
  and t2.column22 = 1;

See SQL Fiddle with Demo

Taryn
  • 242,637
  • 56
  • 362
  • 405
1

You can use Union to eliminate duplicate rows.

SELECT * 
FROM Table1  
WHERE column2 = 1 
union 
SELECT * 
FROM Table2 
WHERE column22= 1;

Refer this to understand what is difference between union and union all.

Community
  • 1
  • 1
DevelopmentIsMyPassion
  • 3,541
  • 4
  • 34
  • 60