Jump to content

Extract column from subquery


silkfire

Recommended Posts

Dunno if I'll get much help here but thought I'd give it a try. I'm running a subquery which returns 2 columns, one with substance and one with status. I then want to run a query on this data set to ONLY get the substance (I need the status as a helper column but need to get rid of it to run an IN query).

 

SELECT set.substance FROM (SELECT substance, (SELECT  parameters.state FROM parameters
				      WHERE products.vnr = parameters.vnr
				      AND parameters.plnt = 'SE20'
                                              AND  parameters.state <> 'passive') as state
                                              FROM `products` WHERE products.substance IN (SELECT substance_mapping.substance FROM substance_mapping WHERE dead <> 'yes')
                                              AND company LIKE '%company%') as set
WHERE set.state <> NULL

 

And get error Subquery returns more than 1 row. It is supposed to return multiple rows, why is MySQL complaining? I have aliases, so what's wrong with the query?

Link to comment
https://forums.phpfreaks.com/topic/237204-extract-column-from-subquery/
Share on other sites

Dunno if I'll get much help here but thought I'd give it a try.

Yes, one of the best ways to get help is to insult everyone before asking your question.

 

Here's a question for you:

 

If you have the information from your first query already why not use that instead of doing another query?

Sorry silkfire know nothing of past sins.  :'(

 

But in this case - you have a query that gives two columns; (right?) one you want; one you don't. So $results give an array with two elements. $array[0] and $array[1]. Why can't you just use one of those for your needs??  :shrug:

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.