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 the 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 there is the column fk_resource_id
. I need all field records returned fk_resource_id
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 much more records and I only used 2 as an example.
- I cannot go to the first query o
fk_resource_id
, since the search is for records that have a certain string in the columnvalue
.
Update: i don’t need to join 2 tables. You need to filter the table by field value
and based on the query result get all records that have the same fk_resource_id
resulting from the first query. Here we have feathers 1 table and the INNER JOIN
joins everything into a single Row, what I need is new Rows, like the above example.
The clause
in
wouldn’t solve it? For example:select * from Tabela where fk_resource_id in (select fk_resource_id from Tabela where value LIKE '%Ent%')
?– Ricardo Pontual
or the Exists clause... puts it in Sqlfiddle that helps when exemplifying
– Rovann Linhalis