For more information, see MySQL Query.

Source: Internet
Author: User
Urgent !!! High score ask MySQL Query problems existing tables A and BA have A column bid that can be blank, corresponding to the primary key auto-incrementing column of Table B if you create A view, the view only displays data with bid not empty. The data in Table A with bid being empty cannot be displayed, it also shows that only one statement is used for data with null bid in Table A. Is there A way to achieve this? How can I write SQLcode? for example, urgent !!! High score ask MySQL Query questions
Existing tables A and B
Table A has A column bid that can be null, corresponding to the auto-incrementing column of the primary key of Table B.
If a view is created, the view only displays data with the bid not empty.
No data is displayed if the bid of Table A is empty.
Now I want to display the data with the bid of Table A being empty.
Is there a way to implement it with only one statement? How to Write

SQL code
  For example: table A --------------- id bid name1 2 abc2 def3 1 ghi Table B ----------------- bid other1 aaa2 bbb if bid of A is associated with bid of B, the result is: ----------------- id bid name other1 2 abc aaa3 1 ghi above A table bid is empty and now the result I want is: ----------------- id bid name other1 2 abc aaa2 def3 1 ghi bbb


High Score

------ Solution --------------------
Search for join left and join right. I believe they can solve your problem.
------ Solution --------------------
Select a. id, a. bid, a. name, B. other from A a left join B B on a. bid = B. bid;

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.