Jump to content

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:

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.