Jump to content

inner query madness


fivestringsurf

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

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.