php - How to UPDATE rows in one table where there duplictaes in another -


If someone can help me write a question to update our order system due to the cheat issue, Grateful on the scale

We have an order table and a customer table

I have identified some duplicate rows in the table of our customers where the email address and password are the same on unique lines - and the customer number Is present in the unique live order that exists in each table. This is bad when a customer enters their account, they will not see all their orders, rather they will only see orders related to the highest customer ID (see the entry below SQL)

Identify fake user accounts:

  select EMAILADDRESS, password, count (*) from join orders.customernumber = customers.CustomerNumber order scustomers where the EMAILADDRESS by = 1 Group , Passwords Counting (*) & gt; Select from: Where the email address: = Email address and password (password: = password)  
  • Update the "Order" table
  • Update " CUSTOMERNUMBER "column
  • Set the" CUSTOMERNUMBER "column to the highest" CUSTOMERNUMBER "
  • Where" Customers "table has more than 1 line with the same" email "and" password " Column

    Where do I start ?!

    Our system has been set up so that any new customer can be logged in by logging in to any customer. The related customer number is therefore about to actually fix the existing data.

    Update:

    I have never used SQL Fuel, but here are some sample data. I hope will help you .. help me Do it!

    Customers:

    CustomNumber, Email, Password

    3272, jwilson@email.com, 9a098e0bade9b4f 2ac4ecdf86111cf7e

    10001, jwilson@email.com, 9a098e0bade9b4f2ac4ecdf86111cf7e

    orders:

    ORDERNUMBER, CUSTOMERNUMBER, status < / em>

    123,457, 3272, 'g'

    123456, 10001, 'G'

    I need to ORDERNUMBER update: the CUSTOMERNUMBER of 123 457 10001 For, 3272 No.

    Step 1: Create a temporary column to store the correct customer number The optional table Add Scotland column is not id_tmp INT;

    Step 2: Right CUSTOMERNUMBER retrieve

      update scustomers inner join (select EMAILADDRESS, password, scustomers group as Max (CUSTOMERNUMBER) ID Duplicate = Duplicate. EMailAdmin and scustomers.PASSWORD = Duplicate.psgword SET id_tmp = id on scustomers.emailaddress as password), by EMAILADDRESS;   

    Step 3: Correct CUSTOMERNUMBER

      Update orders with intermediate orders command: customer.customerNumber = customers.CustomerNumber set scribers include order order table.condition.customenumber = Id_tmp;   

    Step 4: Delete the duplicate customer

      Remove from the customer, where the customcommand is & lt; & Gt; Id_tmp;   

    Step 5: Remove the Temp columns

      Optional table scouts drop column id_tmp;    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -