If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL 4.1.1 subqueries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-13-04, 09:55
Jen76 Jen76 is offline
Registered User
 
Join Date: Jan 2004
Location: California
Posts: 10
MySQL 4.1.1 subqueries

I have just upgraded from 4.0 to 4.1 specifically for the use of subqueries. But they do not seem to be working. I'm getting a MySQL Syntax Error. Help.....


Jen
Reply With Quote
  #2 (permalink)  
Old 01-13-04, 17:04
ika ika is offline
Registered User
 
Join Date: Oct 2003
Location: Slovakia
Posts: 482
Re: MySQL 4.1.1 subqueries

Quote:
Originally posted by Jen76
I have just upgraded from 4.0 to 4.1 specifically for the use of subqueries. But they do not seem to be working. I'm getting a MySQL Syntax Error. Help.....


Jen
Could you post the relevant SQL query and also relevant error?
Reply With Quote
  #3 (permalink)  
Old 01-13-04, 23:47
Jen76 Jen76 is offline
Registered User
 
Join Date: Jan 2004
Location: California
Posts: 10
I used an example subquery from the MySQL handbook...just trying to familiarize myself with them...here's the syntax:

SELECT DISTINCT Cust_ID FROM Cust_Billing_Info WHERE Cust_ID.Cust_Billing_Info IN ( SELECT Cust_ID FROM Customers);

Here's the error:

Failed to execute SQL : SQL SELECT DISTINCT Cust_ID FROM Cust_Billing_Info WHERE Cust_ID.Cust_Billing_Info IN ( SELECT Cust_ID FROM Customers); failed : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT Cust_ID FROM Customers)' at line 1

Now the alternate join syntax works:

SELECT DISTINCT Cust_Billing_Info.Cust_ID FROM Cust_Billing_Info, Customers WHERE Cust_Billing_Info.Cust_ID = Customers.Cust_ID;
Reply With Quote
  #4 (permalink)  
Old 01-15-04, 22:36
donsimon donsimon is offline
Registered User
 
Join Date: Jan 2004
Posts: 24
From a dervived table standpoint this works for sure in 4.1.0 and 4.1.1.

SELECT * FROM Term, (SELECT CONCAT('%', subcategory, '%') as sub FROM SubCategory) subc WHERE term = sub
and Term.vol > 2500 and Term.price > 0.25
ORDER BY Term.price DESC

I would take the individual queries and run them by themselves and make sure they work fine. Actually after just looking at your query, I found the problem.

Your original query:
SELECT DISTINCT Cust_Billing_Info.Cust_ID FROM Cust_Billing_Info, Customers WHERE Cust_Billing_Info.Cust_ID = Customers.Cust_ID;

Your subquery:
SELECT DISTINCT Cust_ID FROM Cust_Billing_Info WHERE Cust_ID.Cust_Billing_Info IN ( SELECT Cust_ID FROM Customers);

The problem by look at it is that you have right after the where clause Cust_ID.Cust_Billing_Info, but based on the select Cust_ID is a field name and Cust_Billing_Info is a table name. So try the query like this.

SELECT DISTINCT Cust_ID FROM Cust_Billing_Info WHERE Cust_Billing_Info.Cust_ID IN ( SELECT Cust_ID FROM Customers);

You should be all setup now.

Donny
__________________
http://www.phpscripts.com/
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On