Category "sql"

Combined SELECT from unnested composite type array and regular column

I have a table my_friends_cards: id | name | rare_cards_composite[] | ---+---------+------------------------ 1 | 'timmy' | { {1923, 'baberuth'}, {1999, 'j

Using REGEXP_Substr in db for more than one condition

Hi i'm using SQL Query in ORACLE db. How can i use the function REGEXP_SUBSTR (oracle SQL) to create a new column with name "VOIE" that contains just the type o

How can I schedule a SQL job in Microsoft Azure SQL Database?

I have one SQL Agent maintenance job which checks the index fragmentation within a database and rebuilds indexes if required. This is running well in my test se

How to pass multiple values into one parameter in stored procedure (Oracle)

I have a parameter created for a stored procedure looking to allow user to pass in multiple inputs. create procedure sp1 (p1 in varchar2) as begin select proc

How to test an SQL Update statement before running it?

In some cases, running an UPDATE statement in production can save the day. However a borked update can be worse than the initial problem. Short of using a test

CREATE VIEW must be the only statement in the batch

I'm trying to make a view. So far, I have written this: with ExpAndCheapMedicine(MostMoney, MinMoney) as ( select max(unitprice), min(unitprice) from

get latest record for each ID

I would like to get the latest record for each server. Here is some example data: TimeGenerated SourceName ComputerName Message 2014-11-22

get latest record for each ID

I would like to get the latest record for each server. Here is some example data: TimeGenerated SourceName ComputerName Message 2014-11-22

Drop default constraint on a column in TSQL

I have a table with a column like this that is currently live: name NVARCHAR(128) NOT NULL DEFAULT '' I am altering the column like this to make it nullable:

MySQL to update an XML attribute

In data load, it seems some XML attributes mapped incorrectly and I'm now trying to correct this, but am struggling with MySQL's handling of this XML column. I

How to convert timestamp with milliseconds to date in Oracle

I have MSSTAMP as "timestamp with milliseconds" in Oracle, format: 1483228800000. How can I cast that milliseconds timestamp into a date format "YYYY-MM", in or

Rounding off to two decimal places in SQL

I need to convert minutes to hours, rounded off to two decimal places. I also need to display only up to two numbers after the decimal point. So if I have minut

Error Code: 1822. Failed to add the foreign key constaint. Missing index for constraint

I found some threads about the error. But all the solutions doesn't work for me. I created 2 tables a user table and one for articles. Now I want to store the

sqlsrv_num_rows() expects parameter 1 to be resource, boolean given

Having an issue with sqlsrv_query. This is the error I get: PHP Warning: sqlsrv_num_rows() expects parameter 1 to be resource, boolean given Here is the relev

mysqldump with --where clause is not working

mysqldump -t -u root -p mytestdb mytable --where=datetime LIKE '2014-09%' This is what I am doing and it returns: mysqldump: Couldn't find table: "LIKE"

SQL query to determine that values in a column are unique

How to write a query to just determine that the values in a column are unique?

Update a column value, replacing part of a string

I have a table with the following columns in a MySQL database [id, url] And the urls are like: http://domain1.com/images/img1.jpg I want to update all

Correct use of transactions in SQL Server

I have 2 commands and need both of them executed correctly or none of them executed. So I think I need a transaction, but I don't know how to use it correctly.

How to insert into a table that specifies a DEFAULT value for every column?

I have a table where all columns are auto-populated whenever an insertion happens: CREATE TABLE … ( ItemID INT NOT NULL IDENTITY(…

In SQL how to count the number of result?

I'm having the following SQL DB: DB name: films DB fields: id, title, release_year, country, duration, language, certification, gross, budget I'm trying to