2012-12-18 32 views
-3

我想知道如何查询此结构: 我怎样才能选择只有一行匹配不同的值

SELECT only 1 ID FROM portfolio 
WHERE category = "x" AND DISTINCT description = 'x'? 

(表名和字段)

portfolio: 
ID, client, section, category, description, year, files 

编辑:谢谢您答案。

+1

一些示例数据? –

+0

哪一行符合你指定的标准? –

+2

请指定您尝试过的查询和错误消息 –

回答

0
SELECT ID from portfolio WHERE category = 'x' AND description = 'x' LIMIT 1; 
+0

谢谢您工作得像魅力 –

1
SELECT MAX(ID) 
FROM profolio 
WHERE category = 'x' AND description = 'x' 
0

你可以像下面那样在mysql中使用limit语句。

select id from portfolio where category='x' and description='x' limit 1 offset 0 
相关问题