Hello, there are two tables, you need to display all the fields of both tables, and the field with the name of the table from which the row is taken. I will try to explain visually:

table1: --------------------- | id | page | data1 | --------------------- teble2: ----------------------------- | id | page | data2 | data3 | ----------------------------- SELECT '@' FROM table1, table2 WHERE page=3 result: -------------------------------------------------- | tablename | id | page | data1 | data2 | data3 | -------------------------------------------------- | table1 | 3 | 3 | test | | | | table1 | 5 | 3 | t | | | | table2 | 2 | 3 | | g13 | others | | table2 | 3 | 3 | | a1 | false | -------------------------------------------------- 

What construction to use on site '@'?

    2 answers 2

     select * from ( select 'table1' as tablename, id, page, data1, null as data2, null as data3 from table1 union all select 'table2' as tablename, id, page, null as data1, data2, data3 from table2 ) X where page = 3 
    • there is something missing here - Gorets
    • one
      Yes, from table1 and from table2 is missing. and so that's right. - Yura Ivanov
    • Added by. :-) - msi
     SELECT table1.*, table2.* FROM table1, table2 
    • somebody, put a minus for it) - MuFF
    • And do not you put yourself? - Modus