I have multiple tables inside my database: Is there a way to keep the columns of all the tables in sync with each other? What I mean is that when I add a new column named ‘last-edit’ inside the first table, this column will duplicate to all the other tables. But the data inside the columns will only be unique
Converting a half-hourly data into Quarter-hourly data by taking mean of half-hourly values in SQL?
I have half-hourly (30 min interval) Data Table in SQL (SSMS). I want to convert it to Quarter-hourly (15 min interval) by taking mean/average of the preceding and succeeding values. What SQL query should I run for it? Answer Using cross apply to convert a single row to a pair of rows
Difference between dm_exec_sql_text vs dm_exec_input_buffer
As per Microsoft docs, dm_exec_sql_text returns the text of the SQL batch that is identified by the specified sql_handle while dm_exec_input_buffer returns information about statements submitted to an instance of SQL Server. I used DBCC INPUTBUFFER for getting the last executed SQL. But it seems both dm_exec_sql_text and dm_exec_input_buffer are replacement DBCC INPUTBUFFER. If this is the case then what
If rows exist in table then return value from table ELSE return a default value. – MySQL
I have to write a query which will return the latest timestamp column’s value from a table if rows exist. If there is no row(s) in table then it return the default value. I have write the following query in MS-SQL which is working fine for me. But , now I need to write this query in MySQL. I have
SQL query to retrieve column name among 3 columns in table whose values are mutually excluse ie.one among them will be ‘Y’ whose col name to be found
I have a query in which multiple joins and select from various tables are used. One table structure is as follows: Only one column among 3 will have the value ‘Y’. Table employee : id valid invalid non-scope 001 Y null null 002 null Y null 003 null null Y The o/p of the select statement for the multiple joins
Copy data on parent and child table
I have two database tables. What I need to do is to copy specific data from one storage to another, but also keep the mapping to the photos. First part I can do easily writing but after that newly inserted items does not have photos. Note, that document_id field is unique for not copied items. Answer Assuming id columns are
How to wirte an select with forigin keys and such
I am about to setup a sql db, not decided yet for mysql, mariadb or postgresql. But before that I have set up my sql script to create the tables I need. First I need help with a sanity check, can you without me see what I am setting up here? Second, the thing I am struggeling with now is
Perform Calculation in MongoDb Query
Supposed I have the collections that contain Event type Product View water_heater View water_heater Purchase water_heater View television View television View television Purchase television There are two types of fields in the first column, (views and purchase) The second column contains different kinds of products. The above data has been imported as a collection in MongoDB database. I want to
Db2: perfomant way to check if item exists
what will be the fastest way to check if a specific item exists in table or not. I am evaluating the result of this select, but will be there a faster and Performance way? Answer This depends on what you want to do with the result. It’s generally not recommended to use aggregate functions, since you don’t need to scan
Count the no of columns with same value in SQL
I have a database MySQL table as following Id Column1 Column2 Column3 First value1 value1 value2 Second value2 value1 value2 I want to retrieve the count of value1 for the row with id First example table as follows Id COUNT(value1) First 2 I searched on google but found posts only regarding counting in one specific column. Can anyone help me