How to make a query depend on the result of the other? [duplicate]

0

Consider the following table:

+----+----------------+----------------+--------+
| ID | fk_resource_id | fk_language_id | value  |
+----+----------------+----------------+--------+
| 1  | 1              | 1              | Entrar |
+----+----------------+----------------+--------+
| 2  | 1              | 2              | Login  |
+----+----------------+----------------+--------+

It is necessary to make a select with filter through columns value and fk_language_id :

... WHERE value LIKE '%Ent%'

The result of the above query will be:

+----+----------------+----------------+--------+
| ID | fk_resource_id | fk_language_id | value  |
+----+----------------+----------------+--------+
| 1  | 1              | 1              | Entrar |
+----+----------------+----------------+--------+

Notice that the fk_resource_id column exists. I need to return all records that have the fk_resource_id field based on the result of the first query.

The result would be as follows:

+----+----------------+----------------+--------+
| ID | fk_resource_id | fk_language_id | value  |
+----+----------------+----------------+--------+
| 1  | 1              | 1              | Entrar |
+----+----------------+----------------+--------+
| 2  | 1              | 2              | Login  |
+----+----------------+----------------+--------+

I know it's the same result as the initial table, but there are 2 points to consider:

  • The original table has many more records and I just used 2 as an example.
  • I can not pass to the first query the fk_resource_id , since the search is for the records that have a certain string in the value column.
  • Update : I do not need to put 2 tables together. You must filter the table by the value field and, based on the query result, get all the records that have the same fk_resource_id that results from the first query. Here we have feathers 1 table and INNER JOIN joins everything in a single row, what I need is new rows, just like the example above.

        
    asked by anonymous 01.03.2018 / 21:14

    1 answer

    1

    The search should be done as follows:

    SELECT
        T1.CAMPO1, T1.CAMPO2, T1.CAMPO3
    FROM
        TABELA T1
    WHERE
        T1.CAMPO2 IN (SELECT T2.CAMPO2 FROM TABELA T2 WHERE T2.CAMPO3 LIKE '%Ent%')
    
        
    01.03.2018 / 21:25