Jump to content

Recommended Posts

Hi all

 

I'm working on a mini revision control system. Each page can have a number of slots to insert data, each slot can have its own name and slots can be of different types. If my table structure looks a bit like this:

 

 

  `id` int(10) unsigned NOT NULL auto_increment,
  `public` enum('y','n') default 'n',
  `page_id` int(10)
  `type` enum('type1','type2')
  `name` varchar(150)
  `data`
  PRIMARY KEY  (`id`)

 

how can I, in one query, pull out all the latest revisions (i'm using the primary key for this - ie, ORDER BY id DESC). in the event that there are two or more records with the same 'page_id', 'type' and 'name', i need to pull out the one with the highest ID.

 

It maybe more simple than i'm making it out to be, but i'm a little rusty with my SQL these days...Hope my question makes sense :)

 

Target machine is MySQL 3.23 if that changes anything...

 

Cheers

Mark

Link to comment
https://forums.phpfreaks.com/topic/62305-query-for-revision-control-system/
Share on other sites

this does the job (or seems to):

 

$query = "SELECT type, name, CONCAT(object_id,type,name) as uniquefield, id, data FROM 
			(SELECT * FROM object_data ORDER BY id DESC) as subq
			WHERE object_id = $object_id
				AND public = 'y'
			GROUP BY uniquefield";

 

but my reservations:

1, it seems a bit 'hacky'

2, it uses subqueries - i'm pretty sure this is probably slower, and also no idea if this works on 3.23

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.