Jump to content

Recommended Posts

I'm tangled in this rather large query and not getting the results I need.

I am expecting a set of results 100 items long.

 

the statement I am having trouble with (I'm getting more than 100 results):

 

SELECT 
        class_item_id 
FROM 
        class_custom 
WHERE
name_abr >= (SELECT name_abr  AS name_abr FROM class_custom WHERE class_item_id = 27 AND class_type_id = 122)
AND
name_abr < (SELECT name_abr +100 AS name_abr FROM class_custom WHERE class_item_id = 27 AND class_type_id = 122)
AND 
        class_type_id = 122

When I hardcode the inner query it works fine ( i get the expected 100 results):

SELECT 
class_item_id 
FROM 
        class_custom 
WHERE
name_abr >= 300
AND
name_abr < 400
AND 
        class_type_id = 122
//works fine! -expected 100 results returned

 

But here's where it gets weird...when I test each subquery individually they seem to return '300' and '400' respectively??? So I'm not sure where I have gone wrong here.

SELECT name_abr  AS name_abr FROM class_custom WHERE class_item_id = 27 AND class_type_id = 122
//returns 300

SELECT name_abr +100 AS name_abr FROM class_custom WHERE class_item_id = 27 AND class_type_id = 122
//returns  400

 

The peices seem to work individually, but not as a whole...Please advise, thank you

 

Link to comment
https://forums.phpfreaks.com/topic/231612-inner-query-madness/
Share on other sites

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.