Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

need to combine these two queries

Question posted by: bips2005 (Newbie) on July 3rd, 2008 05:22 AM
i have got two queries,
Expand|Select|Wrap|Line Numbers
  1. $sql1 = "select cust_id from customer where comp_name = '$compname'";
  2.  
  3.     $result = $DB->query($sql1);
  4.     $result->fetchInto($row);
  5.  
  6.     $sql = "select expirydate from customer l,domain s where l.cust_id = '$row[0]' and s.domname =  '$domname'";


the first query retrieves cust_id from the table customer and i use it in the second query to obtain expirydate.

the problem here is that i need to combine these two queries into a single query to obtain the expiry date.
i am fairly new to this.
r035198x's Avatar
r035198x
Administrator
10,754 Posts
July 3rd, 2008
06:34 AM
#2

Re: need to combine these two queries
Quote:
i have got two queries,
Expand|Select|Wrap|Line Numbers
  1. $sql1 = "select cust_id from customer where comp_name = '$compname'";
  2.  
  3.     $result = $DB->query($sql1);
  4.     $result->fetchInto($row);
  5.  
  6.     $sql = "select expirydate from customer l,domain s where l.cust_id = '$row[0]' and s.domname =  '$domname'";


the first query retrieves cust_id from the table customer and i use it in the second query to obtain expirydate.

the problem here is that i need to combine these two queries into a single query to obtain the expiry date.
i am fairly new to this.

Something like
Expand|Select|Wrap|Line Numbers
  1. "select expirydate from customer l,domain s
  2.  where l.cust_id = (select cust_id from customer where comp_name = '$compname') and s.domname =  '$domname'";

Reply
bips2005's Avatar
bips2005
Newbie
17 Posts
July 3rd, 2008
08:29 AM
#3

Re: need to combine these two queries
thanks that worked...
can we do the same thing using join
or was that one type of join

Reply
Reply
Not the answer you were looking for? Post your question . . .
189,871 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top MySQL Forum Contributors