Category "sql"

MySQL order by field in Eloquent

When I want to define a custom sort order in a MySQL query I can do something like this: ORDER BY FIELD(language,'USD','EUR','JPN') What would be the Eloquen

How to store tree structure in sql?

Here is my schema using sqlite, I am not sure if this is a good way to create tree structure in sql as I have to traverse many time to obtain the entire tree, a

SQL ZOO List each continent and the name of the country that comes first alphabetically

Im confused why it could not be Select x.continent, x.name From world x Where x.name <= ALL (select y.name from world y where x.name=y.name) ORDER BY name

How to convert SQL Server query to MySQL (OUTER APPLY)

I'm trying to switch from SQL Server to MySQL, hence some queries need to be converted. The following SQL Server query gives my desired output: SELECT top 20 c.

SQL error "ORA-01722: invalid number"

A very easy one for someone, The following insert is giving me the ORA-01722: invalid number why? INSERT INTO CUSTOMER VALUES (1,'MALADY','Claire','27 S

Detect SQL island over multiple parameters and conditions

(PostgreSQL 8.4) I got a great introduction to SQL gaps-and-islands here on Stack Overflow but I still have a question. Many island detection CTEs are based on

MySql Query to find out first 50% of records from a Table

I am trying to fetch first 50% of records from a MySQL Table User. I know we can use limit or top for finding them but the total number of records are not fixed

Select a column with a keyword name

I have a table named 'test' It contains a column named 'AND' For that I use the following queries insert into test values ('a','abc'); insert into test value

UPDATE Query without WHERE Clause

Can the UPDATE query be used without a WHERE clause? And if so in what conditions?

Reset Identity Seed ('DBCC CHECKIDENT ... RESEED' is not working)

For my unit tests I have an automated process which builds a copy of a DB, table by table. I first of all run a SELECT INTO and add the primary key and any indi

PL/pgSQL checking if a row exists

I'm writing a function in PL/pgSQL, and I'm looking for the simplest way to check if a row exists. Right now I'm SELECTing an integer into a boolean, which does

Insert into one column by selecting another column in other table but how fill the second column

i have a table which has two columns i'd fill one of the columns by selecting other table column data but how can i fill the next column cause i can't use VALUE

Postgres equivalent for Oracle's DBA_FREE_SPACE and DBA_DATA_FILES

This is the sql query. I need to convert into postgres query SELECT a.tablespace_name, a.maxbytes, a.mbytes, (a.maxbytes - a.mbytes),

PL/pgSQL SELECT into an array

Here's my function declaration and part of the body: CREATE OR REPLACE FUNCTION access_update() RETURNS void AS $$ DECLARE team_ids bigint[]; BEGIN SELECT

How to create Temp table with SELECT * INTO tempTable FROM CTE Query

I have a MS SQL CTE query from which I want to create a temporary table. I am not sure how to do it as it gives an Invalid Object name error. Below is the whol

MS Access - UPDATE SQL Query Error 3061

I try to update data in a table with text delivered from a InputBox. Private Sub editname_Click() Dim GivenNameTB As String Dim EnterName As String Dim SQl

Is there an equivalent to concat_ws in oracle?

I have a ton of columns I am trying to aggregate together and most of them have NULL values. I want to separate values that do appear with a ';' but I cannot fi

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