2

Suppose I have following query:

select e.name, e.city, d.name, d.area
from employee as e
    inner join department as d on e.id = d.eid;

I want the query to get an array response with two array objects.

The first array object Employee should contain the following columns: e.name, e.city.

The second array object Department should contain the following columns: d.name, d.area.

Is there any way to get the data this way? If any so please help me!

Sometowngeek
  • 597
  • 1
  • 6
  • 27
lazyCoder
  • 2,544
  • 3
  • 22
  • 41
  • I removed the inconsistent database tags. Feel free to add the tag(s) for the database you are really using. – Gordon Linoff Aug 05 '16 at 12:01
  • actually i want this in sql and postgres both but main focus on sql – lazyCoder Aug 05 '16 at 12:04
  • Use GROUP_CONCAT http://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html#function_group-concat maybe here you can resolve your problem http://stackoverflow.com/questions/2560946/postgresql-group-concat-equivalent – Vanya Avchyan Aug 05 '16 at 12:07
  • 1
    @BunkerBoy . . . SQL is a language for accessing and managing databases. Postgres is a database that supports SQL. – Gordon Linoff Aug 05 '16 at 12:08
  • The concept of arrays does not really exist in sql. If you want to combine two fields, use whatever method exists in your database engine for concatenating fields. Otherwise, process the results with the application code that is receiving the data. – Dan Bracuk Aug 05 '16 at 12:22
  • does not exist? :( – lazyCoder Aug 05 '16 at 12:39

1 Answers1

0

Try this:

 SELECT
    e.name,
    e.city,
    d.name,
    d.area
FROM
    employee AS e,
    department AS d
WHERE
    e.id = d.eid;
John Smith
  • 7,243
  • 6
  • 49
  • 61
Lokesh Kumar Gaurav
  • 726
  • 1
  • 8
  • 24