2

我有一张桌子和另一张桌子日志ticket中的每一行都有很多日志。我想知道某个字符串是否在某个日志中,然后从票证中获取一个寄存器,无论哪个都没有关系,因为我只想每张获得一行。这是我目前所拥有的:

SELECT ticket.id,ticket.description,ticket.owner 
FROM ticket
JOIN log
ON (log.ticketid=ticket.id)
where log.description LIKE '%someparameter%'

在这种情况下我该怎么办?

4

3 回答 3

2

您可以尝试使用 SQL 限制选项吗?

SELECT ticket.id,ticket.description,ticket.owner 
FROM ticket
JOIN log
ON (log.ticketid=ticket.id)
where log.description LIKE '%someparameter%'
LIMIT 1;
于 2012-11-23T16:08:12.757 回答
1
SELECT
  *
FROM
  ticket
WHERE
  EXISTS (SELECT *
            FROM log
           WHERE log.ticketid = ticket.id
             AND log.description LIKE '%someparameter%'

或者...

SELECT
  ticket.id, ticket.description, ticket.owner 
FROM
  ticket
INNER JOIN
  log
    ON (log.ticketid=ticket.id)
WHERE
  log.description LIKE '%someparameter%'
GROUP BY
  ticket.id, ticket.description, ticket.owner 
于 2012-11-23T16:50:40.663 回答
0

通常的 DB2 等价于 LIMIT 1 是 FETCH FIRST 1 ROWS ONLY:

SELECT ticket.id,ticket.description,ticket.owner 
FROM ticket
JOIN log
ON (log.ticketid=ticket.id)
where log.description LIKE '%someparameter%'
FETCH FIRST 1 ROWS ONLY

您还可以通过以下方式启用 LIMIT 语法:

db2set DB2_COMPATIBILITY_VECTOR=4000

或者:

db2set DB2_COMPATIBILITY_VECTOR=MYS
于 2012-11-23T18:24:04.643 回答