Why duplication of products in prestashop backend - prestashop-1.6

I have more than 1000 products in my store . How can i know the product is a duplicate or not.
when I try to delete one of my product , regardless of deleting the product, some other products are updated.
I found out (if a product have duplicates then ,when deleting any of the product , other duplicate products will be updated.).

You can run an SQL query to find the duplicates rows
SELECT reference, COUNT(*) n
FROM ps_product
GROUP BY reference
HAVING n > 1
ORDER BY n DESC

Related

How to find the the most popular product in graph database?

I have a graph database with the following schema made using Neo4j.
MATCH (customer{customerid})-[:made]->(purchased{Invoiceno, invoicedate})-[:includes{quantity, invoiceamount}]->(product{stockcode, unitprice})
I want the most popular product which is the most customers purchased but I am only able to get the most purchased product by quantity.
MATCH (a:customer)-[r1:MADE]->(b:purchase)-[r2:includes]->(c:product)
WITH SUM(r2.quantity) AS totalquantity, c.stockcode AS productcode
RETURN productcode, totalquantity ORDER BY totalquantity DESC LIMIT 1
This was the result.
╒═════════════╤═══════════════╕
│"productcode"│"totalquantity"│
╞═════════════╪═══════════════╡
│"84077" │3552 │
└─────────────┴───────────────┘
So, how do I get the most popular product based on most customer buying it ?
If a purchase can contain multiple time the same product, you'll need to traverse the full path from the customer and just return the path counts :
MATCH (a:customer)-[r1:MADE]->(b:purchase)-[r2:includes]->(c:product)
RETURN c.id, count(*) AS score
ORDER BY score DESC
LIMIT 1
If a product can be included in a purchase only once, then you can just return the degree of the product for the includes relationship :
MATCH (c:product)
RETURN c.id, size((c)<-[:includes]-()) AS score
ORDER BY score DESC
LIMIT 1

Delete all records that are not the latest

I have a table that deliberately has duplicates in it. In this instance the things that will be duplicated are a deviceId, and the datetime. Sometimes the customer updates their data. The table has three columns, deviceId, datetime and value (there is an incremental primary key). Sometimes when the customer re-evaluates their data, they notice that the value is incorrect, they then update it and send the data for re-processing. As a consequence, i need to be able to delete records that are not the very latest records. I cant do it by datetime, as this will also be duplicated in some cases and I cant truncate the staging table.
To delete the dupes I have the following:
;WITH DupeData AS (
SELECT ROW_NUMBER() OVER(PARTITION BY tblMeterData_Id,fldDateTime, fldValue, [fldBatchId],[fldProcessed] ORDER BY fldDateTime) AS ROW
FROM [Stage.tblMeterData])
DELETE FROM DupeData
WHERE ROW > 1
The problem with this, is it seems to delete a random duplicate.
I want to keep the latest record that is in the staging area and delete any others that are not the latest record. I can then update the relevant row with the new value, with the latest data, when I take it from staging into prod.
is any primary or unique key on the table?
if there's unique id - the easiest way below
not sure about performance but should work ok on small amounts
DELETE FROM DupeData
where id in
(select id from
( SELECT id,
ROW_NUMBER() OVER(PARTITION BY tblMeterData_Id,fldDateTime, fldValue, [fldBatchId],[fldProcessed] ORDER BY fldDateTime) AS ROW
FROM [Stage.tblMeterData])
) q
where q.row > 1)

Joining and filtering out unnecessary data

I need to build a query with the following requirements.
The two tables to use are
MASTER_ARCHIVE and
REP_PROFILE
As of now we are only interested in reps at the wirehouses: Wells Fargo, Morgan Stanley, UBS, Merrill Lynch
To get reps from only these firms, I need to filter the Rep Profile table by Firm ID (The Firm IDs can be found in Firm table), and can filter the Master Archive table on FIRM_CRD
What we need is 2 sets of data:
1) A list of wirehouse reps that are in the Master Archive table, but not in the Rep Profile table
2) A list of wirehouse reps that are in the Rep Profile Table, but not in the Master Archive table
Does anyone have an idea of what type of Joins and filter conditions that I would use to get the data that I'm looking for?
This is what I currently came up with!!!!
SELECT *
FROM MASTER_ARCHIVE E
Left JOIN REP_PROFILE R
ON E.REP_CRD = R.CRD_NUMBER
WHERE E.FIRM_ID IN ('F206','F443','F474','F458')
MINUS
SELECT *
FROM MASTER_ARCHIVE E
JOIN REP_PROFILE R
ON E.REP_CRD = R.CRD_NUMBER
WHERE E.FIRM_ID IN ('F206','F443','F474','F458')
--ORDER BY NAME Name
i don't understand so much, but try with this
SELECT *
FROM MASTER_ARCHIVE E
LEFT JOIN REP_PROFILE R
ON E.REP_CRD = R.CRD_NUMBER
WHERE E.FIRM_ID IN ('F206','F443','F474','F458')
AND R.CRD_NUMBER IS NULL

How to get unique product list?

We have list of category products having duplicate names.
How to get a list of products which should not have duplicate product name in Postgres?
We are searching for min product ids with group by name.
then searching the products in ids.
category = Category.first
ids = Product.select("MIN(id) as id").where(deleted: false).group(:name).collect(&:id)
category.products.where("products.id IN (?)", ids).find_active
How can we optimize the queries?
You can do Product.all.pluck(:name).uniq to get just the product names in an array.
But I think you're solving the wrong problem, in that this problem has a bad 'smell'. If you have products that have identical names, how do you differentiate them from a UX perspective? And why only get the first created product by that name vs. the most 'popular' product? I'm trying to imagine how this solution would work for the user and I'm coming up blank, perhaps because I don't know enough about the context.
Edit: Also, could you clarify what you mean by 'should not have duplicate product name'? Is it to get a list of products, but only the first product if there's multiple products with the same name? Or are you looking for items to correct?
The simple solution in Postgres is with DISTINCT ON:
SELECT DISTINCT ON (name)
id, name -- add more columns if you need
FROM Product
WHERE deleted = FALSE
ORDER BY name, id;
Returns unique product names (sorted alphabetically). From each set of dupes the one with the smallest id. Details:
Select first row in each GROUP BY group?

How do you make a condition on a column in one table apply to every instance of a primary key?

I have a table called 'Artists' which has columns Artist_ID, Artist_Name, Artist_Genre and a table called 'Albums' with Artist_ID, Album_Id, Album_Name, ALbum_Number_Songs etc.
I join these two tables via Artist_Id. Now I want to know all Artists who have never had an album with over 12 songs.
I have tried this:
SELECT Distinct Artist_Name
FROM Artists
INNER JOIN Albums
ON Albums.Artist_ID=Artists.Artist_Id
WHERE Album_Number_Songs < 12
however this just checks all instances and output will be just on whether or not the album has < 12 not the artist overall...does anyone know?
Please try this query:
SELECT Artist_Name FROM Artists
WHERE Artists.Artist_ID NOT IN
(SELECT Albums.Artist_ID FROM Albums WHERE Albums.Artist_ID = Artists.Artist_ID AND Albums.ALbum_Number_Songs > 12)
This also includes the artists with no albums which I think corresponds better to the initial task.
Try this:
select r.artist_name
from artists r
left join albums l on r.artist_id = l.artist_id
group by r.artist_name
having max(l.album_number_songs) <= 12
Note: I have tested this on MS SQL Server, but I think this syntax should work for Oracle and MySQL too.

Resources