0

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

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

4
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by nadnakinam
0
SELECT  * 
FROM $tbl1_name 
WHERE age BETWEEN '$from' AND '$to'
AND sex='$show_all'

Edited by peter_budo: Correcting code tags

0

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?

0

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

0

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.