Page 1 of 1

Get values for just one column from a broader MySQL query?

Posted: Fri Jun 16, 2006 10:18 pm
by fgomez
Hello,

Sorry, I can't come up with a good subject for this question. My PHP-driven website uses a MySQL query that goes something like this:

Code: Select all

SELECT * 
             FROM table
             WHERE type LIKE '%G%'
                AND [a bunch of other stuff]
I have a column in this table called 'area' which contains the key values for another table. What I want to do is throw all values of 'area' that result from the above query (duplicates excluded) into an array. I feel like I should be able to do this without making another call to the database, but I can't figure it out.

Any and all help appreciated.

Thanks!

Posted: Fri Jun 16, 2006 11:06 pm
by feyd

Code: Select all

SELECT DISTINCT `columnName` FROM blah blah blah

Posted: Fri Jun 16, 2006 11:09 pm
by fgomez
So then you do suggest a separate call to the database for this?

Posted: Fri Jun 16, 2006 11:12 pm
by feyd
You posted the question in Databases thus choosing the likely "solution" with that decision. The only other way is iterating over the result set pulling out the values manually.

Posted: Fri Jun 16, 2006 11:16 pm
by fgomez
Thanks for your help. Am I correct to understand that pulling them out manually is slow/inefficient?

Posted: Fri Jun 16, 2006 11:20 pm
by feyd
You would have to do the same for a specific query for the column alone anyways. The difference is consuming less memory in the interim.