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 > Data Access, Manipulation & Batch Languages > ASP > SQL query from Mysql -> Access

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-04, 02:29
hykc hykc is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
SQL query from Mysql -> Access

Hi

I have the following SQL from Mysql and I would like to run it thru ASP+Access

strsql = "select t.* from forum_post p, forum_thread t where p.thread_id=t.thread_id and (0 or (p.post_message LIKE '%test%' or t.thread_subject Like '%test%')) GROUP BY t.tid Order by thread_date DESC"

When I run this query, I got "Cannot group on fields selected with '*' (t)."

How can I make it to work for Access MDB? thanks



Somebody suggested me :

Select forum_thread.* where forum_post.post_message like '%test%' or forum_thread.thread_subject like '%test%' from forum_post inner join forum_post on forum_thread.thread_id=forum_post.thread_id

But it doesn't work as well, error message for this is:
Syntax error in query expression 'forum_thread.* where forum_post.post_message like '%test%' or forum_thread.thread_subject like '%test%''.
Reply With Quote
  #2 (permalink)  
Old 10-12-04, 02:35
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
try this...
Code:
select t.tid , t.* from forum_post p, forum_thread t where p.thread_id=t.thread_id and (0 or (p.post_message LIKE '%test%' or t.thread_subject Like '%test%')) GROUP BY t.tid Order by thread_date DESC
Reply With Quote
  #3 (permalink)  
Old 10-12-04, 02:39
hykc hykc is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Quote:
Originally Posted by rokslide
try this...
Code:
select t.tid , t.* from forum_post p, forum_thread t where p.thread_id=t.thread_id and (0 or (p.post_message LIKE '%test%' or t.thread_subject Like '%test%')) GROUP BY t.tid Order by thread_date DESC
Error:
Cannot group on fields selected with '*' (t).
Reply With Quote
  #4 (permalink)  
Old 10-12-04, 02:46
hykc hykc is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
just give you more detail of my problem

I have 2 tables: forum_thread, forum_post

forum_thread contains:
thread_id
forum_id
thread_author
thread_subject
thread_date
thread_replied

forum_post contains:
post_id
thread_id
forum_id
post_author
post_message
post_date

I need to search post_message and thread_subject
and display the result (show the subject only), just like other forum.
Reply With Quote
  #5 (permalink)  
Old 10-12-04, 02:46
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
what happens if you do this
Code:
select t.tid from forum_post p, forum_thread t where p.thread_id=t.thread_id and (0 or (p.post_message LIKE '%test%' or t.thread_subject Like '%test%')) GROUP BY t.tid Order by thread_date DESC
Reply With Quote
  #6 (permalink)  
Old 10-12-04, 02:48
hykc hykc is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Quote:
Originally Posted by rokslide
what happens if you do this
Code:
select t.tid from forum_post p, forum_thread t where p.thread_id=t.thread_id and (0 or (p.post_message LIKE '%test%' or t.thread_subject Like '%test%')) GROUP BY t.tid Order by thread_date DESC

Error Type:
Microsoft JET Database Engine (0x80040E21)
You tried to execute a query that does not include the specified expression 'thread_date' as part of an aggregate function.
Reply With Quote
  #7 (permalink)  
Old 10-12-04, 02:50
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
so something like...

select forum_thread.thread_subject from forum_thread inner join forum_post on forum_thread.thread_id = forum_post.thread_id where forum_post.post_message LIKE '%test%' or forum_thread.thread_subject LIKE '%test%'
Reply With Quote
  #8 (permalink)  
Old 10-12-04, 03:00
hykc hykc is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Quote:
Originally Posted by rokslide
so something like...

select forum_thread.thread_subject from forum_thread inner join forum_post on forum_thread.thread_id = forum_post.thread_id where forum_post.post_message LIKE '%test%' or forum_thread.thread_subject LIKE '%test%'
This one will work
but It displays duplicate result if I have more than one post which have the search words.

I need to group by same thread and display the subject with the link.
This is the part I can't work out
Reply With Quote
  #9 (permalink)  
Old 10-12-04, 03:05
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
nah you don't....
Code:
select distinct forum_thread.thread_subject from forum_thread inner join forum_post on forum_thread.thread_id = forum_post.thread_id where forum_post.post_message LIKE '%test%' or forum_thread.thread_subject LIKE '%test%'
Reply With Quote
  #10 (permalink)  
Old 10-12-04, 03:18
hykc hykc is offline
Registered User
 
Join Date: Oct 2004
Posts: 8
Quote:
Originally Posted by rokslide
nah you don't....
Code:
select distinct forum_thread.thread_subject from forum_thread inner join forum_post on forum_thread.thread_id = forum_post.thread_id where forum_post.post_message LIKE '%test%' or forum_thread.thread_subject LIKE '%test%'
thanks, works
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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On