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'";
$result=mysql_query($sql);

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'";
$result=mysql_query($sql);

Help me to do this in single subquery...

Thanx in advance...

Recommended Answers

All 9 Replies

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

U done it again Pritaeas...!
Thank You...

i done like this,

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

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

That is not a valid query, but I am unsure of what you want to achieve.

that's horribly inefficient using an inner select on the same table

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.