Query a row in mysql2 tables

Source: Internet
Author: User
Query the statement of mysql2 tables. at the end of this post, table A & nbsp; id & nbsp; & nbsp.

This post was last edited by dxmbxh6 at 14:14:55

Id time title
1 2014-05-01 aaaaaaaaaaaa
2 2014-05-02 bbbbbbbbbbbbbbb

Table B
Id time url
1 2014-05-03 cccccccccccccccccccccccc
2 2014-05-04 ddddddddddddddddddddddd
3 2014-05-05 eeeeeeeeeeeeeeeeeee
4 2014-05-06 fffffffffffffffffffffffffffffffffffffffff

Expected results

Type id date title
A 1 2014-05-01 aaaaaaaaaaaa
B 1 2014-05-03 cccccccccccccccccccccccc
B 2 2014-05-04 ddddddddddddddddddddddd
B 3 2014-05-05 eeeeeeeeeeeeeeeeeee
------ Solution --------------------
This table is designed to be problematic. Unable to implement
------ Solution --------------------
The type field of the result does not exist in both tables. Where does it come from?
------ Solution --------------------

select 'a' as tname , id, time , title from a
union all
select 'b' as tname , id , time ,url from b
order by 2,1

------ Solution --------------------
I don't see any details
Why do Table a's id = 2 and Table B's id = 4 remember to divide it?

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.