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

learn more… | top users | synonyms (2)

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
20 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
16 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
15 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
43 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
42 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
70 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
35 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 ...
0
votes
1answer
38 views

Query must be a SELECT

I try to do a select union with order by but it seem like order by can not use union. I receive following message Query must be a SELECT This is my code (SELECT `tabsales_action`....
0
votes
1answer
20 views

Create a view showing total minutes per customer per month and change from previous month

I have an existing database (SQL Server 2012, on premise installation) and need to add a column to a view which gets displayed via a Crystal Report. The issue I am having is with restricting the ...
1
vote
0answers
37 views

Under which conditions would selecting a small column off a primary key be slow?

Usually querying the table is in the millisecond range at most. But sometimes it takes 30 seconds and then times out. What could cause SELECT smallColumn FROM SomeTable WHERE pkID=@pkID to be slow? ...
0
votes
0answers
37 views

Shrink .ldf file issue

These are the timing of some jobs on SQL-Server: rebuild indexing at 10.30 am (all timing in IST) reorg indexing at 11 am full backup at 12.30 pm transaction backup every 2 hours truncate log ...
1
vote
2answers
46 views

How to find out if rows are refenced from other tables?

I have a table named contacts (primary key id) which is referenced by a number of other tables via foreign keys. When a list of contacts is displayed in the application, I get their primary keys in an ...
1
vote
1answer
12 views

Selecting entries with the same count as in another table

I'm using a SELECT statement to select multiple IDs and than use GROUP BY ID HAVING COUNT(*) = someNumber to only have the IDs with a certain count. What I however actually want to do is to select ...
1
vote
0answers
35 views

UPDATE based on the occurence of the same string within two other columns

I am currently using Microsoft Access 2007. I wonder if there is a way to find whether two specific columns in one table contain the same (undetermined) string. The table may look as follows: ...
0
votes
1answer
16 views

Query to map a particular database to a syslogin

I need to map a database to a syslogin. Following is the query I have used to create login and make it a db_owner but after the execution, I can see a tick as db_owner for that database in ...
0
votes
1answer
39 views

store procedure variable storage takes long time to execute

i have a store procedure This procedure take a endless time for execution BEGIN set @my_user_id=null; select user_id into @my_user_id from office_user where username like my_username ...
0
votes
2answers
22 views

Read CSV and perform SQL in SQL Server Management Studio

Is it possible in SQL Server Management Studio to read a CSV and perform an SQL update per line? Example data.csv "column1","column2,"column3" "column1","column2,"column3" "column1","column2,"...
0
votes
1answer
22 views

Merge sub-queries to a single query

I am trying to merge the nested MYSQL queries into one First of all I fire this query select names , city , category from names_data group by names , city ,category ; this produces a result of ~...
1
vote
1answer
24 views

Get relation data on comma separated values

I am an average in database operation but I never deal with a database having values in comma separated manner. As I want the result from both table. I have one table "Form table" +------+----------...