Help...! (Sub Query)

Thread Solved

Join Date: Sep 2009
Posts: 35
Reputation: nadnakinam is an unknown quantity at this point 
Solved Threads: 0
nadnakinam's Avatar
nadnakinam nadnakinam is offline Offline
Light Poster

Help...! (Sub Query)

 
0
  #1
Oct 7th, 2009
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
  1. $sql="SELECT * FROM $tbl1_name WHERE sex='$show_all'";
  2. $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.
  1. $sql="SELECT * FROM $tbl1_name WHERE age BETWEEN '$from' AND '$to'";
  2. $result=mysql_query($sql);


Help me to do this in single subquery...

Thanx in advance...
Last edited by Ezzaral; Oct 7th, 2009 at 7:03 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 844
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #2
Oct 8th, 2009
  1. $sql="SELECT * FROM $tbl1_name WHERE sex='$show_all' AND age BETWEEN '$from' AND '$to'";
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 844
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #3
Oct 8th, 2009
Duplicate again.
Last edited by pritaeas; Oct 8th, 2009 at 6:02 am.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 47
Reputation: baki100 is an unknown quantity at this point 
Solved Threads: 10
baki100 baki100 is offline Offline
Light Poster
 
0
  #4
Oct 8th, 2009
  1. SELECT *
  2. FROM $tbl1_name
  3. WHERE age BETWEEN '$from' AND '$to'
  4. AND sex='$show_all'
Last edited by peter_budo; Oct 13th, 2009 at 5:10 am. Reason: Correcting code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 35
Reputation: nadnakinam is an unknown quantity at this point 
Solved Threads: 0
nadnakinam's Avatar
nadnakinam nadnakinam is offline Offline
Light Poster
 
0
  #5
Oct 8th, 2009
U done it again Pritaeas...!
Thank You...
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 35
Reputation: nadnakinam is an unknown quantity at this point 
Solved Threads: 0
nadnakinam's Avatar
nadnakinam nadnakinam is offline Offline
Light Poster
 
0
  #6
Oct 8th, 2009
i done like this,

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

I knew it is not better than yours, Pritaeas...
is it right way?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 844
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark
 
0
  #7
Oct 8th, 2009
That is not a valid query, but I am unsure of what you want to achieve.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 47
Reputation: baki100 is an unknown quantity at this point 
Solved Threads: 10
baki100 baki100 is offline Offline
Light Poster
 
1
  #8
Oct 8th, 2009
that's horribly inefficient using an inner select on the same table
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 527
Reputation: network18 is an unknown quantity at this point 
Solved Threads: 61
network18 network18 is offline Offline
Posting Pro
 
0
  #9
Oct 9th, 2009
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
  1. SELECT * FROM $tbl1_name WHERE sex='$show_all and age BETWEEN '$from' AND '$to'
  2.  
It aslo depends upon what you pass as in $from and $to
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 35
Reputation: nadnakinam is an unknown quantity at this point 
Solved Threads: 0
nadnakinam's Avatar
nadnakinam nadnakinam is offline Offline
Light Poster

You are right...

 
0
  #10
Oct 9th, 2009
You are right, its better to not to get complicated...

Thank You for All those who replied...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC