Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Bled w zapytaniu mysl z inner join
Forum PHP.pl > Forum > Bazy danych > MySQL
daniofantasy
mam takie zapytanko co leci do bazy i wybiera wszystkie rekordy (po id), ktore spelniaja kryteria zaawansowanych opcji produktu i gdzies tam sie zagniezdzil blad - ktos pomoze?

zapytanko SQL:

  1. SELECT
  2. SearchFilter.ProductID AS id
  3. FROM
  4. SearchFilter
  5. INNER JOIN
  6. products_to_features products_to_features0
  7. ON
  8. SearchFilter.ProductID = products_to_features0.ProductsId
  9. WHERE
  10. (
  11. (
  12. (
  13. products_to_features0.FeaturedId = "2"
  14. OR
  15. products_to_features0.FeaturedId = "394"
  16. OR
  17. products_to_features0.FeaturedId = "7898"
  18. )
  19. AND
  20. (
  21. products_to_features0.ValueId = "943"
  22. OR
  23. products_to_features0.ValueId = "1588"
  24. OR
  25. products_to_features0.ValueId = "2057"
  26. OR
  27. products_to_features0.ValueId = "2924"
  28. OR
  29. products_to_features0.ValueId = "3288"
  30. OR
  31. products_to_features0.ValueId = "3298"
  32. OR
  33. products_to_features0.ValueId = "3304"
  34. OR
  35. products_to_features0.ValueId = "42458"
  36. OR
  37. products_to_features0.ValueId = "202643"
  38. OR
  39. products_to_features0.ValueId = "13491"
  40. OR
  41. products_to_features0.ValueId = "252913"
  42. )
  43. )
  44. )
  45.  
  46. INNER JOIN
  47. products_to_features products_to_features1
  48. ON
  49. SearchFilter.ProductID = products_to_features1.ProductsId
  50. WHERE
  51. (
  52. (
  53. (
  54. products_to_features1.FeaturedId = "1"
  55. )
  56. AND
  57. (
  58. products_to_features1.ValueId = "1027"
  59. OR
  60. products_to_features1.ValueId = "1030"
  61. OR
  62. products_to_features1.ValueId = "1031"
  63. )
  64. )
  65. )
  66. AND
  67. (
  68. (
  69. SearchFilter.price>=0
  70. AND
  71. SearchFilter.price<=299.99
  72. )
  73. )


Bkled z mysql:

  1. #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner join products_to_features products_to_features1 on SearchFilter.Produ' at line 46


z gory dzieki
Kishin
Po co tam robisz taki zmasowany atak nawiasów to nawet nie pytam ale,
robisz joina po wherze przez co wywala błąd.
kartin
Tak jak napisał Kishin, najpierw JOINy później wyłącznie jeden raz WHERE.

Aby uprościć zapytanie zamiast serii OR użyj IN, BETWEEN też się przyda.
Kshyhoo
Zły dział, przenoszę.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.