Structured Query Language (SQL). For questions about the language, not Microsoft SQL Server (tag sql-server).

learn more… | top users | synonyms (2)

15
votes
2answers
614 views

Does any DBMS have a collation that is both case-sensitive and accent-insensitive?

Note this question is vendor/version agnostic It seems to me, as a speaker (typist, writer) of English, reasonable to expect words to be properly cased but not necessarily have the correct accents ...
3
votes
3answers
263 views

Long running delete query

I have a table with roughly 11 million rows, defined as: CREATE TABLE [sko].[stage_närvaro]( [datum_fakta] [datetime] NULL, [person_id] nvarchar NULL, [läsår_fakta] nvarchar NULL, ...
-4
votes
0answers
24 views

How to populate a value into the null value of two duplicate records, one with some value and the other with the null [closed]

Data: Accnt No: | Trans_id| Amount| Remarks XXXXXXX100 | 501 | 100 | successful XXXXXXX102 | 503 | 5000 | successful XXXXXXX102 | 503 | | successful XXXXXXX103 | 505 | ...
0
votes
0answers
30 views

Subquery or Inner Join?

I have this simple query that finds all transactions from accounts belonging to a specific login, with some extra conditions on the transactions. SELECT t.id, t.date, t.amount, t.description FROM ...
0
votes
2answers
44 views

Slow UPDATE FROM Query in Large Table

I'm currently trying to merge two very large (11 million rows) tables, and my query has been running for over two days with no end in sight. My basic query is: UPDATE us_demand SET ... FROM ...
1
vote
1answer
47 views

Retrieving specific results from a query

I have the following database table Firstname Varchar(40) Surname Varchar(40) Department Binary JobCode Char(1) Normally, pulling the records of a particular department is no problem. The ...
-1
votes
0answers
19 views

some pattern that I can inner join from only one of many kind of tables

I have a very long data form which needs to be saved. additionally, my form data can be separated into 4 kind of form. if I get common columns between 4 types I'll have a table with 48 columns ,...
0
votes
0answers
12 views

Multiple Criteria in Count not working properly

I am trying to create a count query in Access 2010 that counts a column where the parameter Spot in the CityData table is equal to 'Y' and where the last entry in the FeedOut parameter in the ...
0
votes
0answers
20 views

How to return columns when using Dynamic Sql

In my project, i want to search input values and i think i should create a SP using dynamic Sql. When i call this SP in MVC, it return "int".I want it return columns as ProductName,ProductCat ... . ...
0
votes
1answer
22 views

SELECT records based on return of COUNT query

I would like to create a query that returns records if values in a column occur more than once. I came across other Stack Exchange questions but these only dealt with returning the number of ...
1
vote
1answer
35 views

Use stored procedure to get minimum value from column and decrement it and other values

I'm trying to understand how the following algorithm could be completed in SQL 2008 R2. I have a table that contains production data. The table uses a "rolling" scheduling method, meaning that orders ...
5
votes
1answer
39 views

Recover Instance after Log File disk error

This is mainly theoretical, but I would like to have a documented list of options if this happens in the future. Today we had a critical disk error on the SAN, meaning the disk holding the ...
0
votes
0answers
78 views

SQL query runs fast on local computers but slow on production server

I am running a fairly basic query on my local development machine which runs almost instantly. However on the server its taking around 3-4 seconds to return results. I have ran Client Statistics on ...
0
votes
1answer
19 views

Make a boolean false after every n number of minutes in MySQL

I have a table with a boolean value, if that value is not explicitly set to anything in the database for a few minutes by the back-end (django) then it must automatically be set to false. How do I do ...
1
vote
1answer
16 views

Find addresses shared by more than one customer_id where customer_name is is distinct

I need to return the list of addresses that have more than one customer_ID associated with them, exclude the customer_IDs that have the same customer_name and return the number of time the address ...
0
votes
0answers
42 views

Find Intermediate Bus Stop and Source and Destination Bus

I have a table which consists of 4 Columns: PKID, Bus_ID, Stop_Position and Stop_ID. Data: BUS_ROUTE_TABLE PKID BUS_ID STOP_POSITION STOP_ID ------------------------------- 1 1 1 ...
0
votes
1answer
21 views

cant access both phone numbers in my nested table type

Im using Oracle Developer and I have a customers table where each customer has 1 home-phone number beginning with 0131 and either 1 or 2 mobile numbers. I am trying to display the customers name and ...
0
votes
1answer
36 views

Possible to use first CTE as filter for second CTE?

I'm trying to optimize a query on a large database that essentially fetches 50 images for a site and the URL's for the pages they appear on. The current query works okay for smaller sites but larger ...
0
votes
0answers
10 views

Using a view in SQL replication for horizontal filtering

I am setting up transactional replication with more than 200 subscribers. I have read that using a view for horizontal filtering of the rows is best practice so that if you need to change the ...
0
votes
0answers
12 views

Add a new column with new values

I need to ADD A NEW COLUMN with VALUES 'ABC00001234' In this case, all values in the column will be 'ABC00001234' Will the SQL statement add these column&value in the actual DBF? or for just ...
1
vote
1answer
17 views

How to enable odbc connnections in new sql server setup?

Fresh server 2012 R2 Essentials install, trying to get SQL Server Express to accept ODBC connections. My database is setup and I have all of my data populated, but now I am trying to get my reporting ...
1
vote
6answers
434 views

Combining (joining) tables with no key

I have table B and I have Table A. Table B contains records with dates I need to pull. However, I only want to pull them if: They do not exist at all in table A They exist in table A, but only when ...
0
votes
2answers
20 views

SQL server after RAID problems

We had a SQL server die due to some RAID problems. We sent the machine out to a data recovery company and they are able to recover the .MDF and .LDF files from the drives. Will I be able to use ...
0
votes
0answers
24 views

Optimizing query with common parts

I'm creating query that returns list of doctors, that provides a specific service. Here is schema: table user (id, name, user_access_group, is_real_doctor) table servicestypes_groups (...
0
votes
0answers
11 views

storing email address and associated data

I want to save email addresses and for every email address a group of tags. For example: "a1@temp.com", 2 "a1@temp.com", 3 "a1@temp.com", 7 "a2@temp.com", 2 "a1@temp.com", 12 ... What is the best ...
8
votes
2answers
107 views

Increase a counter for each changed row

I'm using SQL Server 2008 Standard, which doesn't have a SEQUENCE feature. An external system reads data from several dedicated tables of the main database. External system keeps a copy of data and ...
0
votes
1answer
14 views

How do I split a long PL/pgSQL line of code over multiple lines?

Is there a way to split a long line of PL/pgSQL code over multiple lines? My context is a trigger function where I log inserts into a table as per: INSERT INTO insert_log (log_time, description) ...
1
vote
0answers
16 views

Create multiple rankings and a table

Here is my problem: I am using SQL for Access 2013; I have a table tbl with some fields Category, Subcategory and Value: Category | Subcategory | Value | | C1 | ...
3
votes
1answer
119 views

How to get max value of a column from one table with its matching record in second table in PostgreSQL?

I have two tables as follows: create table two(grade_id int, edu varchar(20),sortby int); alter table two add constraint pk_one primary key(grade_id); create table one(id int, name varchar(20),...
1
vote
2answers
21 views

issues with creating varchar returning functions [closed]

I have an issue while creating functions in sql server, am very new to sql server Below mentioned is the code which i used, please any issues with syntax. CREATE FUNCTION Fn_Check_Customer_Credit (@...
0
votes
2answers
19 views

How to convert from one type of relationship table to another type

I currently have a relationship table where it's: documentID, dataType, dataID Where documentID is the link to the document file. The dataType is if the data is a specific type of user, for example ...
1
vote
0answers
25 views

SQL On the efficiency of querying data ranges

I'm newish to Sql. In an attempt to make a query more efficient I noticed something strange, the following query, on a single date (where date is a datetime object: SELECT ..., Sum(...)/COUNT(...
0
votes
0answers
9 views

Provide Access to view when access on table is denied

I have a table T1 in database which contains columns C1,C2,C3 AND C4. Of which C1 and C2 contains sensitive information. Access to this table is denied to a group G1. But i need to provide access to ...
0
votes
1answer
25 views

INSERT INTO returns ERROR 1452

I'm trying to move data from one table to another, but having an error: mysql> INSERT INTO activities_article (category_id, created_at, title, promo, content, promo_image_url, coordinates, ...
1
vote
2answers
33 views

Performance issues with partial join query

I have two tables: dbo.allowedURLs (a unique list of all permitted domains) *** DomainName *** google.com facebook.com etc... dbo.loggedURLs (a list of URLs processed by a proxy server) *** ...
0
votes
1answer
23 views

Filtering One column into Different Columns in one statement

I need to SELECT amount FROM table WHERE type='1' AND type='2' AND type'3' Depending on the types, I need them to be pulled into different columns. For example, IF type=1 THEN amount1 IF type=2 ...
0
votes
2answers
47 views

Add database-level collation to PostgreSQL

So I have added a en_US collation to my system: # locale -a C en_US.utf8 POSIX sk_SK.utf8 Based on Postgres' documentation I have added it to my Postgres instance: postgres=# select * from ...
0
votes
1answer
45 views

Using Wildcard with `IN ('%')`?

Is it possible to modify the ('%') to return a single row for the following query, i.e. while keeping the entire statement before it? select 1 FROM DUAL WHERE TRIM('asdfsdf') in ('%')
1
vote
1answer
23 views

How to insert a record returned by a function into a table

I have a plpgsql function that takes one input parameter and returns multiple columns of data as a record. CREATE FUNCTION my_func( IN id bigint, OUT foo bigint, OUT bar double precision ...
-1
votes
1answer
44 views

How to add default constraint in Oracle while altering column [closed]

I'm new in Oracle and my requirement is to port SQL Server statement to Oracle. I want to alter a column with adding a new constraint with a default value. SQL Server Query for the same: ALTER ...
1
vote
2answers
58 views

Problem of SUM of the SUM

When I execute my query I have always the same problem : year_created|month_created|loc_id_1|loc_id_2|loc_id_3|Total ------------------------------------------------------------ 2016 | 7 ...
0
votes
1answer
25 views

SQL Methods Function to add “Gold Medal” for anniversary

I'm trying to create a method function on SQL using Oracle Developer. The member function will give employees a gold medal after 12 years of service to the bank, a silver medal after 6 years of ...
0
votes
0answers
26 views

Oracle sql query add hours and sum results

I ask for your help with the following query in oracle whose function is to bring production speeds boxes. The AVANCEUM field is the real advance in boxes that tien and the theoretical speed is ...
0
votes
1answer
34 views

Is there a way remove SQL Server listener IP on maintenance

Is there a any way to stop listening listener on the SQL Server on production server. I want to be sure nobody is trying to connect my production server when it is maintenance mode. I disabled all ...
0
votes
1answer
44 views

Cannot attach My Database without log file

I deleted my whole database by mistake and all my accounting data is gone. I recovered the .mdf file via FileScavenger. Now when want to attach it without .ldf file it gives this error: Could not ...
1
vote
1answer
17 views

Replacing double digit numbers

I have column with numeric values that I need to replace into text values. I used the sql statement: REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(...
3
votes
2answers
226 views

Difference between “<> ANY(…)” and “NOT = ANY(…)”?

Could you please explain the difference between these two operators? sID != smth and not sID = smth. At a first glance they seem perfectly equal. But they give different results.
2
votes
2answers
71 views

Fastest query for selecting arrays that contain duplicates

I'm using Postgres 9.5 and I have a column, named phones, of type text[]. I need to find all rows where this column contains duplicates. I've found this extremely useful set of functions https://...
0
votes
1answer
31 views

Cumulative Subtraction from external input

I have an external value 20. I need 1 to be subtracted from 20 (=> 19) and then 2 to be subtracted from 19 (=> 17) and so on. Data: Serial No | Value1 | External value(20) A | 1 | ...
0
votes
1answer
36 views

MyBB forum MySql Internal Error :1366

I'm using MyBB forum on my Ubuntu 16.04 LTS server, using LAMP, mySQL Improved to be specific. When I try to install a plugin (by putting it in the mybb plugin folder) and hit install plugin in my ...