944,028 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 730
  • MySQL RSS
Oct 7th, 2009
0

Help...! (Sub Query)

Expand Post »
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
MySQL Syntax (Toggle Plain Text)
  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.
MySQL Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
nadnakinam is offline Offline
58 posts
since Sep 2009
Oct 8th, 2009
0
Re: Help...! (Sub Query)
php Syntax (Toggle Plain Text)
  1. $sql="SELECT * FROM $tbl1_name WHERE sex='$show_all' AND age BETWEEN '$from' AND '$to'";
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,186 posts
since Jul 2006
Oct 8th, 2009
0
Re: Help...! (Sub Query)
Duplicate again.
Last edited by pritaeas; Oct 8th, 2009 at 6:02 am.
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,186 posts
since Jul 2006
Oct 8th, 2009
0
Re: Help...! (Sub Query)
SQL Syntax (Toggle Plain Text)
  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
Reputation Points: 12
Solved Threads: 14
Junior Poster in Training
baki100 is offline Offline
79 posts
since Apr 2009
Oct 8th, 2009
0
Re: Help...! (Sub Query)
U done it again Pritaeas...!
Thank You...
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
nadnakinam is offline Offline
58 posts
since Sep 2009
Oct 8th, 2009
0
Re: Help...! (Sub Query)
i done like this,

MySQL Syntax (Toggle Plain Text)
  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?
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
nadnakinam is offline Offline
58 posts
since Sep 2009
Oct 8th, 2009
0
Re: Help...! (Sub Query)
That is not a valid query, but I am unsure of what you want to achieve.
Sponsor
Featured Poster
Reputation Points: 550
Solved Threads: 731
Bite my shiny metal ass!
pritaeas is offline Offline
4,186 posts
since Jul 2006
Oct 8th, 2009
1
Re: Help...! (Sub Query)
that's horribly inefficient using an inner select on the same table
Reputation Points: 12
Solved Threads: 14
Junior Poster in Training
baki100 is offline Offline
79 posts
since Apr 2009
Oct 9th, 2009
0
Re: Help...! (Sub Query)
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
MySQL Syntax (Toggle Plain Text)
  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
Reputation Points: 29
Solved Threads: 76
Practically a Master Poster
network18 is offline Offline
616 posts
since Sep 2009
Oct 9th, 2009
0

You are right...

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

Thank You for All those who replied...
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
nadnakinam is offline Offline
58 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Trouble using ORDER BY in a UNION statement
Next Thread in MySQL Forum Timeline: INSERT with if function help please





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC