I have a list of tagids and I want to select images and sort them based on how many tags they have that match the list of tagids. I have a query like this: SELECT ImageID FROM Image, WHERE JobID = #arguments.JobID#" What do I need to put in the ORDER BY clause so that this query will sort the imageids in this way?
You need to alter your SELECT statement and COUNT the occurrences of each TagID (if I have understood correctly)
How are the tagIDs link to the imageID? Is it in the same table or a second table? How does the jobID relate to this? Here is a sample statement assuming the following table structure: tblImage - this table represents the images, one row per image -imageID int (pk) -imageName char tblTag - this table represents the tags, one row per tag -tagID int (pk) -tagName char tblImageTags - this table relates the images to the tags, there could be several rows for each image or tag -relationID int (pk) -imageID int (fk) -tagID int (fk) Select imageID, (select COUNT(tblImageTags.tagID) FROM tblImageTags WHERE tblImageTags.imageID = tblImage.imageID) AS tagCount FROM tblImage WHERE xxxxx ORDER BY tagCount I don't know if MySQL lets you do that, but MS-SQL does.