Mysql table Association only obtains the latest data in the joined table.

Source: Internet
Author: User
Table A {id, userId, logTime} Table B {id, userId, dimension mentid, updateTime} Table A is the data record Table B, which is equivalent to the historical record table (dimension mentid of userId before updateTime) currently, table A is associated with Table B, but it can only associate the most recent record that meets the conditions in Table B (also the most recent updateTime before logTime). This is what I do with SELECTA. id, B. userId, B. using mentidfromainnerjoinbona .... mysql

Table A {id, userId, logTime}
Table B {id, userId, dimension mentid, updateTime}

Table A is A data record.
Table B is equivalent to the history table (userId's departmentId before updateTime)

Currently, table A is associated with Table B, but only the most recent record that meets the conditions in Table B can be associated.
(This is also the latest updateTime before logTime)
I did this.
Select a. id, B. userId, B. orders mentid FROM A INNER JOIN B
On a. userId = B. userId and a. logTime> B. updateTime
However, this will retrieve all the data that meets the conditions in Table B, and I only want the most recent one.
Table A and Table B may have multiple userids and dates !!
Solution

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.