MySQL JOIN the most recent row only?

后端 未结 8 1341
傲寒
傲寒 2020-11-28 03:06

I have a table customer that stores a customer_id, email and reference. There is an additional table customer_data that stores a historical record of the changes made to the

相关标签:
8条回答
  • 2020-11-28 03:34

    You can also do this

    SELECT    CONCAT(title, ' ', forename, ' ', surname) AS name
    FROM      customer c
    LEFT JOIN  (
                  SELECT * FROM  customer_data ORDER BY id DESC
              ) customer_data ON (customer_data.customer_id = c.customer_id)
    GROUP BY  c.customer_id          
    WHERE     CONCAT(title, ' ', forename, ' ', surname) LIKE '%Smith%' 
    LIMIT     10, 20;
    
    0 讨论(0)
  • 2020-11-28 03:37
    SELECT CONCAT(title,' ',forename,' ',surname) AS name * FROM customer c 
    INNER JOIN customer_data d on c.id=d.customer_id WHERE name LIKE '%Smith%' 
    

    i think you need to change c.customer_id to c.id

    else update table structure

    0 讨论(0)
提交回复
热议问题