Ask a question about php+mysql.

Source: Internet
Author: User
To query data in a table, the condition is UID in (all-in-one). So satisfying uid=1 or 2 or 3 of the query.
How do I get one condition for each meeting?
For example, the UID is a few of the three, through the SQL query, only the first UID is 1, the UID is the first of 2, the UID is the first of 3.

Reply to discussion (solution)

First of all your data must have an ID, a UID

The query uid is a few: (assuming that the table is named ' User ', there are only two fields in the table, ID and UID, respectively)

Select Id,count (UID) from the user group by UID has uid=1 or uid=2 or uid = 3;

The first of the query UID is 1:

SELECT * from user where uid=1 limit 1;

You can take one of the resulting sets of queries in groups

select * from Tbl_name a WHERE (select count (*) from tbl_name where Uid=a.uid and ID 


each condition takes only one:
Select * from TT where UID in (three-way) group by UID;

Select a.* from Table A where 1> (select COUNT (1) from table B where = b.ID and a.ID > b.ID) and a . UID in (all in a)

select top 1 * FROM table GROUP by ID

Grou P by can implement

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.