Question : Convert MsAccess query to MySQL

I could not get this search query to work in MySQL.

I have MsAccess linked to the tables through ODBC and was able to make it work in MsAccess by saving the first query and including that query in the second. But now (with your help)  I have to get MySQL to do it.

I'm searching several fields in a products table but also want to include extra product fields in the search that have the an unfortunate structure below.

s01_CFM_ProdValues:  has a many to one relationship to s01_Products and contains
field_id, product_id, value, value_long
1   269 1111111111  
4   269 22222222222
6   269     Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor.
9   269 44444444444

s01_Products: this a flat file with fields:
id (key), code, name, descrip
269, 25ps, 25 Piece Back & Body, "Description: These stones bla bla bla bla."

The tables are linked like this
s01_Products.id = s01_CFM_ProdValues.product_id
Each extra field has a number (field_id) an I need to search certain fields.
The actual data is store either in value and value long; never both.

Here is the first MsAccess Query saved as cf_product. It returns multiple records, the fields product_id and the values fields AS combined

SELECT s01_CFM_ProdValues.product_id, [value] & [value_long] AS combined
FROM s01_CFM_ProdValues
WHERE (((s01_CFM_ProdValues.field_id)=4 Or (s01_CFM_ProdValues.field_id)=6));

Here is the  second MsAccess Query saved asProductList_Search

SELECT s01_Products.*, cf_product.combined
FROM s01_Products
LEFT JOIN cf_product ON s01_Products.id = cf_product.product_id
WHERE (
  (s01_Products.active=1) AND (
    (s01_Products.code Like "*Lorem*") OR
    (s01_Products.name Like "*Lorem*") OR
    (s01_Products.descrip Like "*Lorem*") OR
    (cf_product.combined Like "*Lorem*")
  ) AND (
    (s01_Products.code Like "*stones*") OR
    (s01_Products.name Like "*stones*") OR
    (s01_Products.descrip Like "*stones*") OR
    (cf_product.combined Like "*stones*")
  )
)

The results find both "Lorem" AND "stones" in the fields searched.

Answer : Convert MsAccess query to MySQL

without a view...

I recomend you use queries a lot to increase readibility & performance...
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
SELECT cf_prod.*, prod.*, prod.disp_order AS sort_order
FROM s01_Products prod left join
  (
  SELECT cfmp.product_id, CONCAT(cfmp.value, cfmp.value_long) AS combined 
  FROM s01_CFM_ProdValues cfmp 
  WHERE (cfmp.field_id = 4) OR (cfmp.field_id =6)
  ) AS cf_prod on cf_prod.id=prod.id
WHERE (prod.active=1) AND ( prod.id = cf_prod.product_id ) AND
  (
    ( CONCAT(prod.code,prod.name,prod.descrip,cf_prod.combined) LIKE '%BACK%' ) 
    AND 
    ( CONCAT(prod.code,prod.name,prod.descrip,cf_prod.combined) LIKE '%STONES%')
  )
ORDER BY sort_order
Random Solutions  
 
programming4us programming4us