The situation is the following, in the database there are 2 tables:

  1. master (id, name)

  2. employee (id, name)

I want to build a 1 SELECT query for fetching data.

I make a query (merge columns from 2 tables. In one column):

SELECT master.name FROM master UNION ALL SELECT employee.name FROM master 

everything is fine here, but I don’t know how to add more fields to this query.

This is what I mean by:

 SELECT поле23, поле24 + *запрос указанный выше* 
  • You are very strange to link tables and it is not at all clear which fields should be added to the sample. - ilyaplot
  • Well, for example, any column from another table. I can not understand the syntax of sampling queries with UNION - ioszhuk
  • one
    Look towards join - ilyaplot
  • What fields do you want to receive in the end and under what conditions do you want to make a sample? - mJeevas
  • one
    If you combine with UNION, then the fields selected in the two queries must match in type and their number must be the same. Therefore, if you want to bind two selects, then really unite with the help of join. - Ponio

2 answers 2

It seems to me that TS himself does not understand what he wants to do ... Since we are talking about the simplest case, this (apparently) means this:

 SELECT master.name, employee.name FROM master, employee WHERE master.id == employee.id 

In this form, SELECT, at least, has an obvious meaning ...

    The question is very incomprehensible. Supposedly here's an example.

      select "любое значение1", "любое значение2", z.name from (SELECT master.name FROM master UNION ALL SELECT employee.name FROM employee) z where z.name = 'Admin' 

    And what is meant by "I do not know how to add more fields to this query"?