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
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
2answers
122 views

Select highest id of each type in mysql

I am creating a database that keeps track of backups on our various servers. The query that I am using actually seems to work for the most part. The only issue is that it isn't getting the highest ids....
4
votes
2answers
215 views

Should database be denormalized if I need an index across multiple tables

I have a catalog of album and song names. The song has a foreign key to the album table. I expect queries like: SELECT * FROM song s JOIN album a ON a.id = s.album_id WHERE LOWER(CONCAT_WS(' ', album....
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 ...
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 (@...
4
votes
1answer
3k views

Azure SQL Administrator Can't Access Master Database

I created an SQL server and database. I can log in to the database manage page with my administrator account, and manage the database I created, but when I try to look at the master database, it says: ...
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
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 ...
0
votes
1answer
337 views

Data Analysis with MongoDB or MySQL

I have a need for processing some data in order to come up with some statistic. This is the scenario: Each user can answer several questions from the question list. They pick their answers from a ...
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
258 views

SSRS Domain Migration

My company is currently going through a data center migration. We are now down to the SQL Servers and this includes SSRS. The bad thing that is going to hit us is the current SSRS server is being ...
1
vote
4answers
250 views

mysql need help optimizing query

I have a table containing servers logs, and another table containing rules to match certain and drop them. The logs tables contains around 1 million rows, and there are about 20-30 rules. The ...
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, ...
9
votes
0answers
246 views

ROW_NUMBER() OVER (PARTITION BY B,A ORDER BY C) doesn't use index on (A,B,C)

Consider these two functions: ROW_NUMBER() OVER (PARTITION BY A,B ORDER BY C) ROW_NUMBER() OVER (PARTITION BY B,A ORDER BY C) As far as I understand, they produce exactly the same result. In other ...
0
votes
2answers
112 views

“Replicate” sql structure between testing and staging on same database instance

On my local development server I have a database set up which gets hooked into Entity-Framework and is then used for unit testing. Let's call it COMPANY\Database On the same server (and same database ...
-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
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(...
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
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 ...
2
votes
1answer
535 views

Display a one-to-many relationship in one row

I have a "one to many" relationship in two tables: Table "products" contains: product_id, product_descr Table "packing" contains: product_id, package_id, package_desc One product has often more ...
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 ...
2
votes
1answer
2k views

SQL Server recommended MAXDOP settings for NUMA

I have an OLTP SQL Database running on SQL 2008 R2 Enterprise Edition that may be fairly busy (5000 batches/sec) in next couple of months after going live production. Looking into server configuration ...
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
606 views

SSIS Package Execution From Visual Studio Unit Test

Hello I am attempting to run a test which contains the following code: string pkgLocation; Package pkg; Application app; DTSExecResult pkgResults; ...
4
votes
1answer
221 views

Query to determine start and end dates based on time overlap

Given the following data: id | user_id | started | closed | dead ------------------------------------------------------------------------------------------- 7714 ...
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
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 ...
8
votes
2answers
2k views

Convert units of measurement

Looking to calculate the most suitable unit of measurement for a list of substances where the substances are given in differing (but compatible) unit volumes. Unit Conversion Table The unit ...
0
votes
1answer
220 views

Suitable schema to record email sent and response received and invoicing in DB

When a form submission is made on a website: An email with form's details is sent to a set of recipients email addresses stored in a DB. The email contains a link for the recipient to show interest. ...
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 ...
3
votes
2answers
2k views

MySQL - Create a function from another function

I want to create a function same like my old functions. When I create a table, I can use `AS to other table as follows: CREATE TABLE dummy2 AS SELECT * FROM dummy1; Can I do the same thing with ...
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
128 views

Update query for Minimum absolute difference in Access [SQL]

I have 3 tables in an Access db. Table_1 and Table_2 are where the source data comes from and I am filling Table_3. Table_1 has the following fields: Acct_Name Amt Table_2 has the following ...
20
votes
8answers
16k views

How to query a database for empty tables

Due to some 'developers' we had working on our system we have had issues with empty tables. We have found that during the transfer to the cloud several tables were copied, but the data in them wasn't....
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://...
1
vote
1answer
26 views

Efficient way on updating multiple tags or categories

What's the efficient or best way on updating a multiple tags or categories? Currently I have posts and posts_meta tables. I have this structure on posts_meta table: +----+---------+----------+------...
5
votes
2answers
123 views

Grouping by sequential relationships with Postgres

This is quite similar to this question about continuous ranges, and this question about grouping by sequential numbers, but differs in that the sequences are not numeric. Given the following ...
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(...
0
votes
2answers
191 views

sqlite group_concat error while executing query

I have table: CREATE TABLE www ( Col_1 VARCHAR, Col_2 VARCHAR ); select count(*) from www; --1496 And I have error: "Error while executing query: aggregate function are not allowed in ...
0
votes
2answers
172 views

using update query with subquery in Oracle sql

I have an update query where I am trying to update a field but for more than one record, I am trying a join but it doesn't work. Below I get multiple values that come back from the select statement ...
1
vote
1answer
45 views

How can I count some rows before inserting?

Here is my table structure: // QandA +----+----------------------------------------+------+---------+-----------+------------+ | Id | body | type | related | ...
0
votes
1answer
50 views

how to judge sql performance through these two explain?

If I give you 2 explain results from MySQL,how do you know which query is better? the first sql explain *************************** 1. row *************************** id: 1 select_type: ...
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.
3
votes
2answers
248 views

Build Restore History table

We restore a database daily that we download from an FTP site. I would like to build a history table that tracks when the database is restored on our SQL Server. This is easy. My issue is sometime ...
3
votes
2answers
898 views

SQL Server 2008 R2 Mirroring issues

I have this very frustrating problem that I've been trying to figure out for almost a week now. I have two SQL Server 2008 R2 STD w/SP3 box running on Windows 2012 R2 with two instances each, Server1 ...
1
vote
2answers
13k views

exporting oracle tables on command line as sql files

I use exp and expdp to export database tables on command line but it generates binary .dmp files. I want to export/import tables as .sql* files on command line like pl/sql developer app can do. Is ...