I am working with SQL Server 2014 Express Edition and I have the following query.
SELECT DISTINCT T.ProductoCatalogoId AS Id, T.ProductoId,
CONCAT(T.Nombre, ' | ', T.TALLA, ' | ', C.COLOR) AS Descripcion, T.PrecioVenta, T.CATALOGO AS Nombre
FROM
(
SELECT PC.ProductoCatalogoId, PC.ProductoId, P.Nombre, O.NombreOpcion AS TALLA, PC.PrecioVenta, C.Nombre AS CATALOGO
FROM Productos AS P
JOIN ProductoCatalogos AS PC ON P.ProductoId = PC.ProductoId
JOIN EspecificacionCatalogos AS EC ON PC.ProductoCatalogoId = EC.ProductoCatalogoId
JOIN Opciones AS O ON EC.OpcionId = O.OpcionId
JOIN Especificaciones AS E ON EC.EspecificacionId = E.EspecificacionId
JOIN Catalogos AS C ON PC.CatalogoId = C.CatalogoId
WHERE P.Nombre LIKE '%VESTIDO PIQUE%' AND EC.EspecificacionId = 5
) AS T
CROSS JOIN
(
SELECT PC.ProductoCatalogoId, PC.ProductoId, P.Nombre, O.NombreOpcion AS COLOR, PC.PrecioVenta, C.Nombre AS CATALOGO
FROM Productos AS P
JOIN ProductoCatalogos AS PC ON P.ProductoId = PC.ProductoId
JOIN EspecificacionCatalogos AS EC ON PC.ProductoCatalogoId = EC.ProductoCatalogoId
JOIN Opciones AS O ON EC.OpcionId = O.OpcionId
JOIN Especificaciones AS E ON EC.EspecificacionId = E.EspecificacionId
JOIN Catalogos AS C ON PC.CatalogoId = C.CatalogoId
WHERE P.Nombre LIKE '%VESTIDO PIQUE%' AND EC.EspecificacionId = 2
) AS C
The result of that query is the following:
Putting in the LIKE the full or almost complete name (WHERE P.Name LIKE '% DRESS PIQUE%') gives me an exact result as we are seeing in the image.
But what happens when I just put the word DRESS? It brings me inconsistent data I show you an image where I put the full name and then I just put the word DRESS.
The way I work with that search form is as follows:
How can I solve the problem I have in the above lines ?, I think if I put a GROUP BY at the end of the query to EC.ProductCatalogueId can bring the data so I only put the word DRESS.
The other problem is that when I add the GROUP BY at the end of the query it asks me to add all the fields that are in the selection query.
The model I have is the following, I have a Catalog to be able to sell and I have to enter the products in the catalog, the products go in ProductCatalog, there are products that have specifications and products that do not have specifications.
When the product has specifications, it is added in ProductSpecifications, such as size and color, of course, before it is due to create size and color in Specifications which is related to Options in this table are the colors (red, black , yellow, etc) and size (s, m, l, xl, etc), then when a product has specifications from the Catalog you are given catalog specifications and there you register what size and colors it takes.
Complicates only when I search for products that have specifications (it is complicated in the sense that to bring me the exact specifications I have to put the full name of the product, as long as I do not do that as for example I put on dress and on the db I have several products that start with dress the specifications are not exact until I complete the name of the product).
I see that if I do not put the full name it will not give the exact result.
NOTE: In PIQUE DRESS there is no yellow and green color in my database, when I put ONLY DRESS.
I hope you can help me.
Greetings!