简体   繁体   中英

Create a 'timeline' with multiple tables (SQL)

I'm trying to create a timeline of action that the user did (when I use his email address).

Example:

  • Subscribe to the newsletter (16/12 09h00)
  • Open the newsletter (16/12 10h22)
  • Click on a link (16/12 10h34)
  • Click on a link (16/12 10h37)

I've 3 tables I want to use in my timeline:

  • landing (landing_email, landing_date)
  • tracker (tracker_email, tracker_date)
  • links (links_email, links_date)

So, the only common point is the email address (and the column has a different name in each table).

I've tried a lot of solutions but they didn't work with my case.

You can use a UNION like:

SELECT Email, DateTime FROM
  (SELECT landing_email as Email, landing_date as DateTime FROM landing 
   UNION 
   SELECT tracker_email as Email, tracker_date as DateTime FROM tracker
   UNION
   SELECT links_email as Email, links_date as DateTime FROM links)
WHERE EMAIL='user@domain.com'
ORDER BY DateTime;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM