Current location: Hot Scripts Forums » Programming Languages » PHP » sql problem


sql problem

Reply
  #1 (permalink)  
Old 05-20-05, 08:55 AM
da.bass da.bass is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
sql problem

hi,
i'm having a serious sql problem:

My table layout looks like this (simplified):
content: name, version, data / primary key is (name,version)
theme: contentname, name

The only thing I have is theme.name.
What I want is all the data inside content that corresponds to theme.name and has the maximum version.

Example:
I have name = 'test'. This gives me the contentnames 'content1' and 'content2'.
Now I want the data of 'content1' with the maximum version (which e.g. is 5) and the data of 'content2' with its maximum version (which e.g. is 24).

To do this in more than one query is no problem, but I want to do this in one single query. I tried multiple possibilites using 'group by', 'havin', subselects... but still can't get a working query.

hope this problem could be solved soon
thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 05-20-05, 11:57 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
I am not quite sure what you mean since you didn't specify in which table the name = 'test'..
anyway, check out the mysql function MAX() and ORDER BY DESC ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 05-24-05, 06:00 AM
da.bass da.bass is offline
Newbie Coder
 
Join Date: Jul 2003
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
OK, I found one solution, but I'm not sure if it will work in all cases:
Code:
SELECT name as a, data, version FROM content
WHERE name IN (
  SELECT contentname FROM theme
  WHERE name = 'test'
)
AND version = (
  SELECT max(version)
  FROM stylesheets
  WHERE name = a
)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Statement problem jetskibum ASP 1 08-16-04 07:41 AM
SQL infinite loop problem with VB application Syed Visual Basic 2 05-07-04 11:19 AM
Problem Dealing with Null Valuers in SQL Query hai_anilreddy Visual Basic 3 02-08-04 09:39 AM
Help with ASP & FORMS blessedrub ASP 0 01-23-04 11:22 AM
change my field in this example sal21 ASP 3 07-14-03 03:49 AM


All times are GMT -5. The time now is 09:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.