0

Hey all, I am wondering what the best way to do the following is:

Query up to 5 tables (depends on user input) pull back the results and return a single array. Lets say I query table A and have the results stored as a result handle (return from the pg_query() fn), shall I go ahead and convert those to an array, and then continue appending the results from the subsequent queries to that? If so can I get away with simply using the array_merge() function?

3 Answers 3

1

Sounds like you want a UNION.

Sign up to request clarification or add additional context in comments.

2 Comments

I would rather query each table (actually a view) independently and then join the results using PHP, hence my thought of using the array_merge() fn.
Okay. Then yes, array_merge() is what you want.
0

use a union:

SELECT col1, col2
  FROM a
 UNION
SELECT col1, col2
  FROM b

Comments

0

Using a UNION might be the answer only if your results are going to be low. UNION's are a little taxing on the DB server and some DB's have a hard time optimizing them. By using a Store Procedure or Making 5 Queries then doing an array merge, will allow the DB server to cache some results and improve DB performance.

If the result set is going to be low and there are not going to be much calls, then using a UNION should be fine.

1 Comment

The result set will be in the 10s of thousands.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.