[英]PHP & MYSQL - How To Check If Two Or More Rows Have The Same Field Value
So here's the problem I can't work around today. 所以这就是我今天无法解决的问题。
I want to grab some details from a database. 我想从数据库中获取一些细节。 I'm not sure how to explain this.
我不知道如何解释这一点。 But here goes.
但是这里。
Database Example: 数据库示例:
1 | 1 | Description |
说明| abc
ABC
2 | 2 | Description |
说明| abc
ABC
3 | 3 | Description |
说明| def
高清
I want to select the first row with the identifier "abc" and then I want to skip the next row which has the same field "abc". 我想选择标识符为“abc”的第一行,然后我想跳过具有相同字段“abc”的下一行。
I'm trying to use this in a SELECT mysql_query in PHP 我正在尝试在PHP中的SELECT mysql_query中使用它
To get the complete row you can do 要获得完整的行,您可以执行此操作
select * from your_table
where title in
(
select min(title)
from your_table
group by identifier
)
This? 这个?
SELECT DISTINCT(identifier), title, description FROM tablename
It will also return the row with 'def' in this case. 在这种情况下,它也会以'def'返回行。
It appears that the integer field is called 'title'. 似乎整数字段称为“标题”。 This should grab the lowest title # but remove the duplicates as you requested.
这应该抓住最低标题#但是按照您的要求删除重复项。
select min(title) as firstTitle, description, identifier
from table_name
where identifier in (select distinct identifier from table_name)
group by description, identifier.
select min(TITLE) as TITLE, DESCRIPTION , IDENTIFIER
From your_table
Group by DESCRIPTION , IDENTIFIER
select id, description, identifier
from table group by identifier order by id asc;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.