Having
Company id Name 1 Enron 2 Walmart Employee id Company 2 1 3 1 4 2 5 2 6 2
I want to get
Enron 2,3 Walmart 4,5,6
so far I wrote:
select Company.Name, Employee.id from Company inner join Employee on Company.id = Employee.Company group by Company.id
but the current result is
Enron 2 Walmart 4
The SQL standard provides the CONCAT() function to concatenate two strings into a single string. SQLite, however, does not support the CONCAT() function. Instead, it uses the concatenate operator ( || ) to join two strings into one.
The syntax for the SQLite CROSS JOIN is: SELECT columns FROM table1 CROSS JOIN table2; NOTE: Unlike an INNER or OUTER join, a CROSS JOIN has no condition to join the 2 tables.
MySQL | Group_CONCAT() Function. The GROUP_CONCAT() function in MySQL is used to concatenate data from multiple rows into one field. This is an aggregate (GROUP BY) function which returns a String value, if the group contains at least one non-NULL value. Otherwise, it returns NULL.
To append a string to another and return one result, use the || operator. This adds two strings from the left and right together and returns one result. If you use the name of the column, don't enclose it in quotes. However, in using a string value as a space or text, enclose it in quotes.
Use Group_Concat:
select Company.Name, Group_Concat(Employee.id) from Company inner join Employee on Company.id = Employee.Company group by Company.id
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With