Posts | Comments

So I’m still working on all that SQL stuff - now it’s up to figuring out how to get the multiple keyword search going again.

I have a method, not sure how efficient it is (I’m going to run some tests) but so far it’s working.

  1. /****** GETTING A LIST OF IMAGES BACK *****/
  2. SELECT
  3. it.Filename,
  4. it.Record_ID AS Record_ID,
  5. it.Path,
  6. it.File_Description,
  7. "image_server" AS database_name,
  8. "1" AS using_databases,
  9. "1" AS databaseID
  10. FROM
  11. image_server.Item_Table it
  12. JOIN
  13. image_server.Item_Keyword ik
  14. ON
  15. ik.Item_ID = it.Record_ID
  16. JOIN
  17. image_server.Keyword k
  18. ON
  19. k.Record_ID = ik.Keyword_ID
  20. WHERE
  21. k.Keyword = ‘dog’
  22. AND
  23. ik.Item_ID IN (
  24. SELECT
  25. ik.Item_ID
  26. FROM
  27. image_server.Item_Keyword ik
  28. WHERE
  29. ik.Keyword_ID = (SELECT
  30. k.Record_ID
  31. FROM
  32. image_server.Keyword k
  33. WHERE
  34. k.Keyword = ‘cat’) )

Update: I figured I’d use that search method above for now until I find a better method.
That’s not the end of my troubles, however. I’ve got some issue with a JOIN statement that’s not returning the right result set (the right row):

  1. SELECT
  2.         sl.id,
  3.         sl.userID,
  4.         sl.insertdate,
  5.         sl.searchString,
  6.         sl.galleryID,
  7.         sl.imageType,
  8.         sl.imageColor,
  9.         sl.databaseID,
  10.         sl.using_database,
  11.         sg.Name,
  12.         db.dbcommonname
  13. FROM
  14.         CE_search_log2 sl
  15. JOIN
  16.         Saved_Galleries sg
  17. ON
  18.         sl.galleryID = sg.Record_ID
  19. JOIN
  20.         CE_dblist db
  21. ON
  22.         db.id = sl.databaseID
  23. WHERE
  24.         sl.userID = ‘cedge’
  25. ORDER BY
  26.         sl.insertdate DESC
  27. LIMIT 0,1
  28. – returns search ID # 186  
  29.  
  30. SELECT * FROM CE_search_log2 ORDER BY insertdate DESC LIMIT 0,1
  31. – returns search ID # 194

If you notice, the first query returns the CE_search_log.id row of 186. The second query returns the correct row of 194. I think it might be because of my join statement, but I’m not sure. Argh, frustrating!

Update (again): Looks like it was a JOIN problem. I needed a LEFT JOIN for the CE_dblist line. D’oh!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Technorati

Leave your comment

chadedge dot-com is powered by WordPress. Design by Nofie Iman.