Data comparison between two tables (php + mysql)

Source: Internet
Author: User
Data comparison between two tables (php + mysql) table_aid, code1, xiaoming2, daniu3, sige5, wangqiang6, limingtable_bid, aid1, 6. I want to display the following results, the contents of Table A corresponding to Table B are highlighted. 1: Data comparison between two tables (php + mysql)
Table_a
Id, code
1, xiaoming
2, daniu
3, sige
5, wangqiang
6. liming

Table_ B
Id, aid
1, 2
2, 3
3, 6
The following figure shows the effect. the content of Table A corresponding to Table B is highlighted:
1, xiaoming
2, daniu
3, sige
5, wangqiang
6. liming

Ask experts for solutions.

------ Solution --------------------
Select a. id, a. code, B. aid from a outer join B on a. id = B. id order by a. id asc
Then, you can highlight the value of B. aid.
------ Solution --------------------
The upstairs method is feasible.
------ Solution --------------------
SELECT
A. id, a. code,
(Case when B. id IS NULL THEN 'n' 'else' END) AS IsHight
FROM
A
Left join B ON a. id = B. id
Order by a. id

If the IsHeight value is 'Y', it is highlighted.

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.