Understanding Data Combination in MySQL

Asked 2 years ago, Updated 2 years ago, 143 views

The following databases are available:Please let me know if there are any SQL statements that combine the same names but lack data.
Examples of databases and their output

mysql database

2022-09-30 21:29

1 Answers

The point is to group by name.

If you do not have the same column value,

select
    name
   , max (address)
   , max (phone number)
from customer DB
group by name

I think that would be fine.

If you have the same column value,

select
    name
   ,group_concat(address) as address
   , group_concat (phone number) as phone number
from customer DB
group by name

If so, the addresses and phone numbers will be concatenated and output separated by ,.


2022-09-30 21:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.