SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old November 24th, 2003, 06:42 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
rewriting a query with subquery to one without a subquery

hello....i have a bit of a problem. I have the following sql query:

SELECT t1.topicid,t1.forumid,t1.titel,t1.slotje,p1.timest amp
FROM topic t1, post p1
WHERE t1.forumid = $forum and
p1.forumid = $forum and
t1.topicid = p1.topicid and
p1.timestamp = (
select max(timestamp)
from post
where forumid = $forum and
topicid = p1.topicid)
order by p1.timestamp desc

the problem is the mysql server i use doesnt support subqueries. Can anyone help me find a different sql query that does the same without a subquery?

Reply With Quote
  #2  
Old November 24th, 2003, 07:05 PM
zackcoburn zackcoburn is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 184 zackcoburn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: rewriting a query with subquery to one without a subquery

There really isn't a way you can do it with one query, to my knowledge.

http://www.mysql.com/documentation/...olumn-group-row

The link above might give you some insight as to the most efficient way to handle this situation.

Reply With Quote
  #3  
Old November 25th, 2003, 09:46 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
RE: rewriting a query with subquery to one without a subquery

If your server does not support subquries, you should do it in two queries.
Generaly if you are looking just for one value, use variable to hold it.
If you are looking for more max values (for example from every forum), use array (or something like that) to hold them. And if you want to do it only in database, just use temporary tables.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > rewriting a query with subquery to one without a subquery


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway