Kusto Query to merge tables - azure-data-explorer

I am new here for Kusto Query Language. I am exploring few concepts of Azure Data Explorer and I would to like to write a function that performs the merge (as we do in SQL). I tried few queries, but data is only inserting as new records and this is creating the duplicate data in my ADX table.
Below is my requirement.
I have a employee_temp table, where I keep the data from different sources. Once data comes into this table, it should merge with my main table employee.
** When target table (employee) has a record already with empid, then perform update.
** When target table (employee) do not have a record with empid, then perform insert.

Sounds like you're looking for a materialized view with an arg_max aggregation.

Related

How to save query results to a new sqlite?

I want to save the results of my sqlite query in a new sqlite file. in other words, I want to have a new sqlite database with the data which resulted from my query on my previous data set.
All I have found on the internet was how to export the query results to csv or sql. but I want my new data set to be sqlite.
Also, is there any way to save the query results on the same data set (like what we do in excel)? Thank you!
You can ATTACH another database file to an existing connection and create or insert data into a table in that other database.
Something like:
ATTACH DATABASE 'other.db' AS other;
CREATE TABLE other.foo AS SELECT * FROM main.foo; -- create and populate a table
INSERT INTO other.bar SELECT * FROM main.foo; -- insert into an existing table
DETACH other;

How to do a batch update in sqlite3 database

All:
I am pretty new to SQL, I wonder how can I update certain field value across multiple tables in SQLITE3 database?
For example:
the database is company.db, inside it, there are 50 tables, each table has a column called company_name, now some company's names changed, so I need to update that info in all tables, I wonder how to do it in SQL?
Thanks

Change a large dynamodb table to use LSIs instead of GSIs

I have a live table in dynamo with about 28 million records in it.
The table has a number of GSI that I'd like to change to be LSIs however LSIs can only be created when the table is created.
I need to create a new table and migrate the data with minimum downtime. I was thinking I'd do the following:
Create the new table with the correct indexes.
Update the code to write records to the old and new table. When this starts, take a note of the timestamp for the first record.
Write a simple process to sync existing data for anything with a create date prior to my first date.
I'd have to add a lock field to the new table to prevent race conditions when an existing record is updated.
When it's all synced we'd swap to using the new table.
I think that will work, but it's fairly complicated and feels prone to error. Has anyone found a better way to do this?
Here is an approach:
(Let's refer to the table with GSIs as oldTable and the new table with LSIs as newTable).
Create newTable with the required LSIs.
Create a DynamoDB tirgger for the oldTable such that for every new record coming to the oldTable insert the same record to the newTable. (This logic needs to be in the AWS Lambda).
Make your application point to the newTable.
Migrate all the records from oldTable to newTable.

Batch filling in lookups in MS Access

I'm copying quite a lot of data from Excel into Access. The trouble is, I have a lookup field and I must select a value from it for each new row. There are about 1000 rows and I wondered if I can somehow fill in those lookups automatically.
Create a linked table to the Excel. Let's call it ExcelLinked.
Create a query with ExcelLinked and your lookup table, let's call it tblLookupItems.
The query will be:
INSERT INTO TargetTable (SELECT ExcelLinked.*, tblLookupItems.ID FROM ExcelLinked INNER JOIN tblLookupItems ON ExcelLinked.LookupItem = tblLookupItems.LookupItem)
However, if there are values in the Excel file that do not exist in the lookup table, you will have to decide whether you are willing to forgo those rows or use a lookup ID of 0 in which cae you should use a LEFT JOIN in the SQL query.

Asp.net MVC3 with LINQ to SQL on multiple identical tables

I successfully retrieved data from an already populated table of a live database using mvc3 and linq 2 SQL. The table is defined in the DataClasses1.dbml.
Now I have to retrieve data from other tables with the same identical structure of DataClasses1 but from different databases on the same SQL Server( DB1.Customers DB2.Customers ecc), and display them grouped by database name.
1) How can I do that without creating N DataClassesN.dbml ? I guess since it's the same table structure I can avoid doing it.
2) (Optional): How can I automatically retrieve data also from tables of new created databases?
3) (Not relevant): How can I define a strongly type view? Seems I can do it using EF but I cannot do it using LINQ 2 SQL.
I already thought of creating a view on the database with all the customers tables, but it seems it's a too heavy view!
I have a query that returns all the database names (Select name from master..syttables), is it useful?
Thanks in advance
You just pass a different connection string to the data context when you create it. If the databases are truly identical, including all the foreign key relationships, then just do something like:
var dc = new DataClasses1(db1connectionstring);
// Do your display of database 1 data
var dc2 = new DataClasses1(db2connectionstring);
// Do your display of database 2 data
I have no idea what you mean by #2. Data doesn't retrieve itself.
You can't obviously join results from 2 databases in SQL so you'd probably have to use 2 queries (one to each database) with one of them selecting into a new Entity of the other database and then join the results in memory using LINQ afterwards. So one query returns DB1.EntityName and the other returns DB2.EntityName but with a select mapping this to new DB1.EntityName entities and then join the two. It's not a pretty solution but is the best I can think of off the top of my head.
If you just want each database to have a set of results each then obvioulsy you can just return 2 result sets. Let me know if I misunderstood your question.

Resources