hi to all,

this might be very simple, but i don;t know how to get correct output, someone help me to complete it...

1st i need to get result from this query

$sql="SELECT * FROM $tbl1_name WHERE sex='$show_all'";

this'll result either all the boys or all the girls;

from the above result again i need select according to their age using this 2nd query.

$sql="SELECT * FROM $tbl1_name WHERE age BETWEEN '$from' AND '$to'";

Help me to do this in single subquery...

Thanx in advance...

Edited by Ezzaral: Added [code] [/code] tags. Please use them to format any code that you post.

8 Years
Discussion Span
Last Post by nadnakinam
FROM $tbl1_name 
WHERE age BETWEEN '$from' AND '$to'
AND sex='$show_all'

Edited by peter_budo: Correcting code tags


i done like this,

$sql="SELECT * FROM $tbl1_name WHERE username='$name' IN (SELECT * FROM $tbl1_name WHERE sex=$sex01)";

I knew it is not better than yours, Pritaeas...
is it right way?


why to complicate the simple query, he just have two simple reuirements on the same table as -
1)age BETWEEN something AND something
and 2)sex as all on same table

SELECT * FROM $tbl1_name WHERE sex='$show_all and age BETWEEN '$from' AND '$to'

It aslo depends upon what you pass as in $from and $to


You are right, its better to not to get complicated...

Thank You for All those who replied...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.