Ask a question about php+mysql.

Source: Internet
Author: User
Ask a question about php+mysql.
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.
------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;

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

Where (select COUNT (*) from tbl_name where Uid=a.uid and ID
------Solution--------------------
Only one rule is taken for each condition:
SELECT * from the TT where UID in (n/a) group by UID;
------Solution--------------------
Select a.* from table A where 1> (select COUNT (1) from table B where a.id = b.ID and a.id > b.ID) A nd a.uid in (All-in-all)
------Solution--------------------
Select top 1 * from table GROUP BY
------Solution--------------------
Group by can achieve
  • 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: info-contact@alibabacloud.com 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.