database query question - PostgreSQL

Discussion in 'OT Technology' started by beez, May 2, 2008.

  1. beez

    beez New Member

    Joined:
    Jun 3, 2004
    Messages:
    19,143
    Likes Received:
    0
    Location:
    Queens
    This seems like a querying 101 task but I never took any courses so who knows.

    I have two tables from which I want to perform a single query. I expect a single row to be returned from table1, and multiple rows to be returned from table2.

    I want to put the multiple rows from table2 into an array so that when I get my result back from the query, I get a single row with the table2 data in said array. How do I do that?
     
  2. SLED

    SLED build an idiot proof device and someone else will

    Joined:
    Sep 20, 2001
    Messages:
    28,118
    Likes Received:
    0
    Location:
    AZ, like a bauce!
    well the sql part is pretty standard
    Code:
    SELECT col1, col2, etc
    FROM table1 
       INNER JOIN table 2 ON table1.col = table2.col
    
    where the tableX.col is the common field to join across

    your 2nd question about putting said results into an array is going to depend largely on the language you are using :dunno:
     
  3. beez

    beez New Member

    Joined:
    Jun 3, 2004
    Messages:
    19,143
    Likes Received:
    0
    Location:
    Queens
    I did this: SELECT ... ARRAY(SELECT table2.col FROM table2 WHERE table1.id = table2.id)... It returns a string to PHP that looks like {res1,res2,res3,...,resN}. Just trim and explode and we're good.
     

Share This Page