我需要创建一个SQL查询,该查询根据该列中的值以及其他列中的一个列返回多个值。 我有2张桌子 table 1 Table 2
我当前的查询是
SELECT title, id, value, item_id, catid, created, field_id, alias
FROM gewtk_content p
INNER JOIN gewtk_fields_values ON p.id = item_id
WHERE `value` = 'Jessica' AND `title` REGEXP '/ESD'
AND `state` = '1' AND (`field_id` = '265'
OR `field_id` = '297' OR `field_id` = '301'
OR `field_id` = '301' OR `field_id` = '302'
OR `field_id` = '303' OR `field_id` = '304')
按预期工作 但是,我还需要返回“值”列中的条目,其中field_id = 186和与上述查询结果中的item_id相匹配的item_id条目。在这种情况下,item_id = 532 因此,使用表中的数据和上面的查询,结果将是
<table style="height: 108px;" width="740">
<tbody>
<tr style="height: 31px;">
<td style="width: 75.7833px; height: 31px;">title</td>
<td style="width: 75.7833px; height: 31px;">id</td>
<td style="width: 75.7833px; height: 31px;">value</td>
<td style="width: 75.7833px; height: 31px;">item_id</td>
<td style="width: 75.7667px; height: 31px;">cat_id</td>
<td style="width: 75.7833px; height: 31px;">created</td>
<td style="width: 75.7667px; height: 31px;">field_id</td>
<td style="width: 75.7833px; height: 31px;">alias</td>
</tr>
<tr style="height: 39.7333px;">
<td style="width: 75.7833px; height: 39.7333px;">positive/ESD</td>
<td style="width: 75.7833px; height: 39.7333px;">532</td>
<td style="width: 75.7833px; height: 39.7333px;">jessica</td>
<td style="width: 75.7833px; height: 39.7333px;">532</td>
<td style="width: 75.7667px; height: 39.7333px;">24</td>
<td style="width: 75.7833px; height: 39.7333px;">2019-04-03 05:41:3</td>
<td style="width: 75.7667px; height: 39.7333px;">265</td>
<td style="width: 75.7833px; height: 39.7333px;">positive-esd-18</td>
</tr>
</tbody>
</table>