Update MySQL table after merging rows - mysql

After executing the following code:
SELECT
industry,
company,
GROUP_CONCAT(symbol SEPARATOR ',') AS symbol
FROM
table1
GROUP BY
SOUNDEX(company),
I managed to merge some rows, however the table isn't updating itself with the merged rows and cells.
I then tried using UPDATE / SET / WHERE but not quite sure what to SET and WHERE as I need to update every merged row/cell. The "best error" that I get is Operand should contain 1 column(s)
I'm now quite stuck here.. any hint at how to update the table would be much appreciated.
EDITED
Some more details:
I'm making a PHP code that can feed data from xml to database, then look for duplicate entries and merge it like this:
here is the snapshot of my DB table:
When I run code above code through PHP - there are no changes to the above DB table
But when the code is executed directly in phpMyAdmin "SQL", the following changes can be seen:
But when I click back to "Browse", all data stays as it was.
Thus it let me think that it is not updating after I did merging...

Related

Pentaho Kettle (Spoon) - Delete Records From Different Tables

I'm trying to delete records in my target table based on whether records exist in source table. I tried using a 'Delete' step, but I noticed that this step is based on a conditional clause.
My condition is quite simple "if the record/row does NOT exist in table A [source], delete the record/row from table B [destination]".
I also read about using a 'Merge Rows (diff)' step, but it seems to check/compare the entire set of tables for differences.
The table has several million records with many hundreds of columns in a MySQL server, I need to do this in the most efficient way.
I'm doing a search of table A with the Table input object and sql command:
'' ' SELECT I went , user , password , attribute , op FROM viewuserradiusunisulma
Any help would be appreciated.
print - image screen pentaho transformation
Transformation
Delete Pentaho
if your source and target table are in the same database, you can use a SQL query to delete all records in tableB that don't have a corresponding entry in tableA:
delete tableB where not exists (select id from tableA where id = tableB.id)
if source and destination tables are not in the same database, you would have to go through all rows in tableB and check whether the record exists in tableA. If your source tableA has a limited number of rows, loading the key values in memory and then performing a stream lookup instead of a database lookup would be much faster. I'd probably try that even with higher number of rows because of the significant performance impact.
note: I hope I haven't messed up the sql syntax, I'm thinking almost exclusively in abap at the moment and that messes with my memory a bit. So please test this on some backup before firing away.
I found the solution. In this case, I check the records, then report, update and enter the new data
Trasnsformation

Combine INSERT and SELECT in one SQL query (Zapier)

I'm crafting Zapier task to insert entry in MySQL if there is no entry with specified unique key or do nothing.
I need to try to insert new row into some table, but if email of new entry is already INSERT will silently throw warning (due to IGNORE keyword).
INSERT IGNORE users(email, hashed_password)
VALUES ('<email>`, '<some_hashed_password>')
But in both scenarios my query is not returning anything and Zapier ends task with this message:
Question: Is there some way to have one complex SQL command that will combine INSERT and SELECT so with one query I will get some result set from from DB, not empty object or whatever INSERT returns?
P.S. This works in MySQL:
INSERT IGNORE reporting.users(`email`, `password`)
VALUES ("test#test.ts", "test");
SELECT * FROM reporting.users as u WHERE u.email = "test#test.ts";
but this consists of two queries and this doesn't work in Zapier.
This is an old question but I was grappling with the same issue today. In trying to find a solution I came across this qn and so when I found a solution / work-around I thought I'd do the decent thing and post back...
Based on the red "Bargle" error in their post I believe zmii must have been trying to use the MySQL custom search query. Zapier has to have an output from the query or it faults. I did some looking around and crafted my custom query thus:
SELECT IFNULL( (SELECT employee_id FROM timesheets.employees WHERE employee_id = <Step 6 | sheet_data_id> LIMIT 1) ,0) AS result;
based on the selected answer here.
So, my query will output an employee ID if it is found and 0 if not. I then inserted a Zapier PATHS step which I based on the output 'result' from my custom query. If the result is greater than 0 I update an existing record. If it is 0 then I insert a new record. I suspect I could use the custom query code to do the branching and updating/inserting but I didn't try that yet as I have other things to try first.
Edit
Actually I have had to revise this answer based on my conversation with Zapier here. I've retained the original answer but hidden it. The syntax works but only if the query is a SELECT query, it will not work for an INSERT or UPDATE query. See the discussion in the comments of the linked question for details. Essentially it is not possible to do an insert or update operation via the Zapier MySQL Custom Query step at this stage.

transfer data from 1 table to another in the same database

Is this the right syntax:
INSERT INTO stock (Image)
SELECT Image,
FROM productimages
WHERE stock.Name_of_item = productimages.number;
SQL Server Management Studio's "Import Data" task (right-click on the DB name, then tasks) will do most of this for you. Run it from the database you want to copy the data into.
If the tables don't exist it will create them for you, but you'll probably have to recreate any indexes and such. If the tables do exist, it will append the new data by default but you can adjust that (edit mappings) so it will delete all existing data.
I use this all the time and it works fairly well.
INSERT INTO bar..tblFoobar( *fieldlist* )
SELECT *fieldlist* FROM foo..tblFoobar
This just moves the data. If you want to move the table definition (and other attributes such as permissions and indexes), you'll have to do something else.
The query logic that you are trying appears to be not correct (the query itself is buggy).
Assuming you have the correct query for the above logic and what you are trying is to insert new rows into the table stock by selecting a column from productimages table with a matching record as stock.Name_of_item = productimages.number
The above logic will add redundant data in to the table.
You perhaps looking to update instead of insert, something as -
update stock s
join productimages p on p.number = s.Name_of_item
set s.Image = p.Image

Unable to do an INSERT INTO using a SELECT where the SELECT is `information_schema`.`COLUMNS`

This one really stumps me. I'm trying to create a MySQL query that I can populate information into a columns table to then export into SQLite. I can populate just about anything I want, except when the SELECT statement comes from information_schema.COLUMNS.
Here's a simple example to test. I created a table called TestTbl in a schema called and gave it 2 rows. The first is an AUTO INCREMENT INT id row, and the 2nd is a varchar 100 row called Namedb. I then run the following query.
INSERT INTO `tblinfoetc`.`testtbl` (Namedb)
SELECT
`COLUMNS`.`TABLE_SCHEMA` AS `Namedb`
FROM
`information_schema`.`COLUMNS`;
My message after doing this is:
Affected rows: 0
Time: 0.000s
If I run this without the INSERT INTO line, it returns the records without a hitch. Any ideas?
This is more of a workaround suggestion than a real solution:
Selecting from information_schema.columns works fine, so try doing the operation in two steps. First, copy the data using a client interface then insert it into the destination table from the client.
I have encountered the same problem on a windows machine running mysql 5.6.13. The query used to work with mysql 5.5. It might be related to this other issue

Update + Append Query in Access 2007

I'm working on a database right now and I have a pretty specific problem that I'm trying to figure out:
I have a large master table in my database with all the info we're gathering. We're updating records in this master table based on Excel files returned to us by various team members across the company - all of the records have unique ID numbers so we know what fields in the master table to update. We are tracking who responds by updating the file name into the master table as well. I want to update this with the file name; however, if two sources give me the same data, I want to append the second file to the first file rather than replace it with an update.
The problem is, I need the query to "know" when to update and when to append. Is there some IF statement I can use - maybe Update when Null, Append when Not Null?
You can refer to an Excel sheet or range in a query:
INSERT INTO Table1 ( ADate )
SELECT SomeDate FROM [Excel 8.0;HDR=YES;DATABASE=Z:\Docs\Test.xls].[Sheet1$a1:a4]
WHERE SomeDate Is Not Null
This means that you can run queries based on the presence or absence of data in the Excel file.