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 > inline view ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-04, 05:19
daytripper daytripper is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
inline view ?

This is the query that works on MS SQL server, but I can't get to work in MySQL:

SELECT ss, COUNT(DISTINCT ra) AS theCount
FROM (SELECT DISTINCT searchStr AS ss, remote_addr AS ra FROM tbl_savesearch) tb
GROUP BY ss
ORDER BY theCount DESC

table looks like this:

table tbl_savesearch
id, searchStr, remote_addr, was_answered

Tried to find an answer in the documentation, but the only thing I could find that is wrong is that mysql needs an "as" before the "tb" after the second inline query.

What do I need to change?
Reply With Quote
  #2 (permalink)  
Old 02-04-04, 09:57
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
What was the error message?
Prior to version 4.1 MySQL does not support subselects.
select version();
Reply With Quote
  #3 (permalink)  
Old 02-04-04, 12:46
daytripper daytripper is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
ah, yes that seems to be the problem:

"[MySQL][ODBC 3.51 Driver][mysqld-3.23.58]You have an error in your SQL syntax near..."

Is there some other way to get the same result?
Reply With Quote
  #4 (permalink)  
Old 02-04-04, 12:58
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
This should do the same thing:

DROP TABLE IF EXISTS tmp;
CREATE TEMPORARY TABLE tmp
SELECT DISTINCT searchStr as ss, remote_addr as ra
FROM tbl_savesearch;

SELECT ss, COUNT(DISTINCT ra) AS theCount
FROM tmp
GROUP BY ss
ORDER BY theCount DESC;

DROP TABLE tmp;
Reply With Quote
  #5 (permalink)  
Old 02-09-04, 05:00
daytripper daytripper is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
Actually I couldn't get that to work either, this is the error message:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[MySQL][ODBC 3.51 Driver][mysqld-3.23.58]You have an error in your SQL syntax near ';CREATE TEMPORARY TABLE tmp SELECT DISTINCT searchStr as ss, remote_addr as ra F' at line 1

I tried adding a semicolon after "create temporary table tmp" too, but that made no difference...
Reply With Quote
  #6 (permalink)  
Old 02-09-04, 10:08
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
Try running all those SQL queries w/o the terminating semicolon (.
Reply With Quote
  #7 (permalink)  
Old 02-09-04, 10:11
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
And run each of the four SQL queries in a separate ODBC statement (don't jam them all together in one ODBC statement).
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