Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 383017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:14:31+00:00 2026-05-12T15:14:31+00:00

My company is working with 3 partners and each partner can have multiple brands.

  • 0

My company is working with 3 partners and each partner can have multiple brands. Each week, I get a dump of each brand’s user list
which I store in a MySQL database with a table for each brand. Each brand contains a list of users and some basic information
(birthyear, zip code, gender). Some users can be signed up with different brands and each brand can have it’s own set of data on a user.

For example, a user is signed up with Canvas and MNM. At Canvas, their profile looks like this:

ID                                  GENDER  BIRTHYEAR   POSTCODE    MODIFIED
94bafdb3e155d30349f1113a25c0714f    M       1973        2800        2009-01-01 09:01:01

and at MNM, like this:

ID                                  GENDER  BIRTHYEAR   POSTCODE    MODIFIED
94bafdb3e155d30349f1113a25c0714f            1973        1000        2009-09-09 09:01:01

I’d like to create a view (or table – I’m not sure which is best) that would combine the two records using the most recent version of the data, but also letting me know where the data came from.

So the above two records would combine to:

ID                                  GENDER  G_DATE              G_BRAND BIRTHYEAR   B_DATE              B_BRAND POSTCODE   P_DATE               P_BRAND
94bafdb3e155d30349f1113a25c0714f    M       2009-01-01 09:01:01 Canvas  1973        2009-09-09 09:01:01 MNM     1000       2009-09-09 09:01:01  MNM

I’m imagining some convoluted series of unions and sub queries, but I’m not even really sure where to begin.

I’ve created a view that merges all of the tables

CREATE VIEW view_combine AS
SELECT ID, GENDER, MODIFIED as G_DATE, 'Canvas' as G_BRAND, 
    BIRTHYEAR, MODIFIED as B_DATE, 'Canvas' as B_BRAND, 
    POSTCODE, MODIFIED as P_DATE, 'Canvas' as P_BRAND FROM canvas
UNION ALL
SELECT ID, GENDER, MODIFIED as G_DATE, 'Een' as G_BRAND, 
    BIRTHYEAR, MODIFIED as B_DATE, 'Een' as B_BRAND, 
    POSTCODE, MODIFIED as P_DATE, 'Een' as P_BRAND FROM een
UNION ALL
SELECT ID, GENDER, MODIFIED as G_DATE, 'MNM' as G_BRAND, 
    BIRTHYEAR, MODIFIED as B_DATE, 'MNM' as B_BRAND, 
    POSTCODE, MODIFIED as P_DATE, 'MNM' as P_BRAND FROM mnm

and then I’m trying to perform selections on that, but I don’t think it’s the right direction.

SELECT v1.hashkey, ge.gender, ge.g_date, ge.g_brand, 
    bi.birthyear, bi.b_date, bi.b_brand, 
    pc.postcode, pc.p_date, pc.p_brand
FROM view1 v1
JOIN ( 
    select g.hashkey, g.gender, g.g_date, g.g_brand 
    from view1 g 
    left join view1 g1 ON g.hashkey = g1.hashkey AND g.g_date < g1.g_date 
    WHERE g1.hashkey IS NULL
) ge ON ge.HASHKEY = v1.HASHKEY
JOIN ( 
    select b.hashkey, b.birthyear, b.b_date, b.b_brand 
    from view1 b 
    left join view1 b1 ON b.hashkey = b1.hashkey AND b.b_date < b1.b_date 
    WHERE b1.hashkey IS NULL
) bi ON bi.HASHKEY = v1.HASHKEY
JOIN ( 
    select p.hashkey, p.postcode, p.p_date, p.p_brand 
    from view1 p 
    left join view1 p1 ON p.hashkey = p1.hashkey AND p.p_date < p1.p_date 
    WHERE p1.hashkey IS NULL
) pc ON pc.HASHKEY = v1.HASHKEY
GROUP BY v1.hashkey
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:14:31+00:00Added an answer on May 12, 2026 at 3:14 pm

    I’ve managed to solve this. Essentially, I needed to select on the view and then sub-select on the view to get the fields I wanted. I found that ordering on the date within the sub-select returned the values I needed.

    SELECT v1.hashkey, ge.gender, ge.g_date, ge.g_brand, 
        bi.birthyear, bi.b_date, bi.b_brand, 
        pc.postcode, pc.p_date, pc.p_brand
    FROM view_combine v1
    JOIN ( 
        select g.hashkey, g.gender, g.g_date, g.g_brand 
        from view_combine g 
        left join view_combine g1 ON g.hashkey = g1.hashkey AND g.g_date < g1.g_date and g1.gender is not null
        WHERE g1.hashkey IS NULL
        order by g.g_date
    ) ge ON ge.HASHKEY = v1.HASHKEY
    JOIN ( 
        select b.hashkey, b.birthyear, b.b_date, b.b_brand 
        from view_combine b 
        left join view_combine b1 ON b.hashkey = b1.hashkey AND b.b_date < b1.b_date and b1.birthyear is not null
        WHERE b1.hashkey IS NULL
        order by b.b_date
    ) bi ON bi.HASHKEY = v1.HASHKEY
    JOIN ( 
        select p.hashkey, p.postcode, p.p_date, p.p_brand 
        from view_combine p 
        left join view_combine p1 ON p.hashkey = p1.hashkey AND p.p_date < p1.p_date and p1.postcode is not null
        WHERE p1.hashkey IS NULL
        order by p.p_date
    ) pc ON pc.HASHKEY = v1.HASHKEY
    GROUP BY v1.hashkey
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with a small theatre company. Currently they have a list of
I have a rather theoretical question. My company has a working standard (documented) that
I have 2 date object in the database that represent the company's working hours.
I am curently working on a Company entity which contains a List of Area
In the company i'm working on we have releases every x amount of time
I have a simple tab page, php sdk working and I know I can
We have a development company we are working with that wants to use VB.NET
The company I'm working at does not have a great Infrastructure, it is treated
I am working with a Chinese brand company and would like to remove some
I have a table, that contains employees. Since the company I'm working for is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.