DO NOT USE this for questions targeting Microsoft SQL Server, use the tag sql-server instead. "SQL" is an acronym for "Structured Query Language", it is used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. ...

learn more… | top users | synonyms (1)

0
votes
0answers
24 views

Sql*PLUS: Output each field as a new line

Right now the configuration I have is the following: set pagesize 0; SET NULL *NULL*; SPOOL output/output.txt I am outputing the results to a text file in order to run a function on the file to ...
1
vote
1answer
18 views

Stop PostgreSQL from logging statements on error

My postgresql 9.3 logs are sprinkled with entries like these (redacted to protect the guilty): STATEMENT: INSERT INTO table (key, value) VALUES ($1, $2) ERROR: duplicate key value violates unique ...
0
votes
1answer
22 views

Select max value from many to many tables

i have next tables in may data base: I want to select the book that has the max number of pages for each author. I did this : select auteur.nomauteur, auteur.prenomauteur ,livre.Title, ...
0
votes
2answers
34 views

Counting unique records across 2 columns and computing a score based on boolean values

I have a table that looks like this in Google Big Query: custID InteractionDate Purchased? Sales 1 20150312 F 0 1 20150312 T 200 1 20150314 ...
1
vote
1answer
161 views

Alias using “AS” and without using “AS” [closed]

What is the difference in accessing a table with alias "AS" and without using "AS". Is there any performance enhancements? For Example : SELECT S.ID,S2.Value FROM dbo.Sample AS S INNER JOIN ...
2
votes
0answers
29 views

Tuple Relational Calculus help? [closed]

I have the following three questions in relation to the following diagram: 1) How many copies of the book titled “The Lost Tribe” are owned by the library branch whose name is "Sharpstown"? ...
0
votes
1answer
15 views

What impact do queries have on a server's resources?

This is a really ignorant question, but I'm wondering what impact queries have on a server's resources in general and can't seem to find a straight answer through searching. For example, suppose a ...
0
votes
1answer
20 views

How to split a row based on a delimiter into multiple rows and retain the ID and ordering by using a single SQL statement for MySQL

Scenario: A MySQL table A Delimiter (e.g. comma) is used to separate entities inside a string store in a column of the MySQL table MySQL table contain 2 columns - ID and Countries_Involved ...
0
votes
1answer
18 views

Uniq join 3 tables with relationship table not uniq

I am using Postgres. I have 3 tables: table_1 id table_1_2 table_1_id, table_2_id table_2 id The problem is the relationship table table_1_2 is not uniq. I.e., table_1_2 will have the ...
2
votes
1answer
54 views

Add linked server from SQL Server 11.0.5058 to SQL Server 10.50.4000 [closed]

I tried to add a linked server running on SQL Server 2008 R2 (10.50.4000) from SQL Server 2012 (11.0.5058). I keep getting this error: The linked server has been created but failed a connection ...
0
votes
1answer
23 views

Creating Database Tables for Reviews functionality that incorporates Tags/Categories

I'm wanting to create some simple website functionality through a little database idea I have in order to give myself the ability to create/retrieve customer reviews based upon tags/categories. More ...
2
votes
2answers
36 views

DB2 sorting by lowercase uppercase - problem

I'm struggling with DB2 - sorting by Polish letters with diacritics and uppercase/lowercase. When I created a database using: CREATE DATABASE P1DS8 AUTOMATIC STORAGE YES ON '/home/db2inst1' DBPATH ...
0
votes
2answers
24 views

Get ID which has two rows with different values for one column [closed]

Basically, I have a dataset that is a list of internal location identifiers attached to an ID (so each 'set' of geographical points has its own ID). So an 'id' column and a 'location' column exist in ...
0
votes
1answer
59 views

Separating working hours with non-working hours SQL [closed]

Please can someone assist? I need to break up data between working hours and non-working hours (weekends also need to be taken into consideration). I'm not really sure where to begin, other than: ...
1
vote
0answers
18 views

SQL - Optimize table population with dynamic queries

I need to optimize the following pl/sql procedure. So, fundamentally my question is: There is a way you can do a bulk insert in a pl/sql that could be more efficient than loop through an associative ...
6
votes
2answers
157 views

Count data using multiple date ranges

Probably this has been asked before, but I can't figure it out. I have a phone_clicks table (sql fiddle http://sqlfiddle.com/#!15/855e0/1) CREATE TABLE phone_clicks ( id integer NOT NULL, ...
0
votes
1answer
43 views

SQL database normalisation within C#

Ok so I don't have code for this as I am unsure of how it would even go. Take this scenario I am working on. A purchase system for let's say tires. I have one table named tStock and another one for ...
0
votes
1answer
35 views

Distinct rows by order

I have the following SQL, generated from ActiveRecord in Rails 4 (partly with the Geocoder gem) problem is, that even though DISTINCT is used, hopefully to get only unique items, the items returned ...
0
votes
0answers
41 views

SQL Server performance is slow when migrated from SQL Server 2012 to SQL Server 2014

We are trying to migrate from SQL Server 2012 to SQL Server 2014 on Windows 2012 R2 OS. After the upgrade, we are doing performance testing and observed huge difference in running a simple query from ...
3
votes
0answers
32 views

Can an active session in oracle be dead?

I have a time consuming query which populates a materialized view. It has been running for 18 hours - which was not expected. SELECT STATUS FROM V$SESSION WHERE SID=194; The above query shows the ...
0
votes
1answer
46 views

use parameters in a Cte

I want to use parameters in the below cte but I get the below error messages Msg 102, Level 15, State 1, Procedure X82 7 Days/by Day, Line 5 Incorrect syntax near '('. Msg 137, Level 15, State 2, ...
0
votes
0answers
45 views

How to find pairs of attributes who did the same thing in a same entity?

For example, there are 4 tables below: User(uid, user_name) Friend(uid, friend_id) Like(pid, uid) Post(pid, uid, text) And my question is how to find pairs of user and his friend who have liked ...
0
votes
1answer
49 views

What is the best query to get the latest row version based on time?

I'm wondering what can be the most efficient query to get the latest rows from the following table. CREATE TABLE AGE_DATA ( INSERTED_DAY TIMESTAMP(6), HOSTNAME VARCHAR2(255 CHAR), CONCEPT ...
2
votes
3answers
126 views

Aggregate query with min

Having a product_stock table with following structure: product_id warehouse_id stock price Which has bunch of records (same product can be in different warehouses): 1, 1, 0, 500 1, 2, 5, 505 1, 3, ...
0
votes
1answer
18 views

SQL Help in Aceess

How can I write an SQL in Access that shows the manager's Last and First Name, salary of the manager based on the Department and Budget? EMPLOYEE PK FK: ...
3
votes
1answer
216 views

how can an additional natural join with the same table twice *reduce* the row count

This is real results from my database. I spend some time trying to reproduce this behavior with an SSCCE but failed. How is the last of the below results possible? SELECT COUNT(*) FROM rr.resource ...
0
votes
0answers
30 views

Log shipping Readonly/Standby executes Queries slow for some users

I have a SQL Server database that is doing log shipping to another SQL Server instance, both servers have identical hardware. We have a reporting service that then runs reports against the readonly ...
2
votes
2answers
49 views

Adding Users after Database Restore

I have to restore our production database to a test instance on a daily bases. This test instance gives people access to the data that we do not want changing production data. When I restore the ...
0
votes
1answer
18 views

How to define destination for an append query Microsoft Access

I'm trying to append two tables in MS Access at the moment. This is my SQL View of my Query at the moment: INSERT INTO MainTable SELECT FROM Table1 INNER JOIN Table2 ON Table1.University = ...
0
votes
1answer
15 views

Access querry with “last” and display the rest too [closed]

I have an Access DB about measuring tools. I have 2 tables: tblTools, which countains the details of the device, the tblCalibration contains the which device when was calibrated. I made a query of ...
-1
votes
4answers
52 views

What permissions does db_owner not have? (In SQL Server 2008) [closed]

Can you list the permissions that db_owner cannot do.
2
votes
1answer
44 views

How do I retrieve the loop record in the connect by clause?

I have a employee-->Manager hierarchy and using the following query: SELECT EMP_ID, FIRST_NAME CONNECT_BY_ISCYCLE "CYCLE" FROM MYTABLE CONNECT by NOCYCLE PRIOR MANAGER_EMP_ID = EMP_ID START WITH ...
0
votes
2answers
19 views

Single select from template record oracle

Due to lack of terminology in my head, let's say I've got 1 record from users table with these attributes : Name | Surname | Height | Weight Person X 6,2 190 How do I find other ...
2
votes
1answer
38 views

Find string of decimal digits in Pi

I am trying to find the first occurrence of "12345" in the decimal expansion of $\pi$ by using MySQL. Possibly by using the Instr function? But I am stuck because it only displays the first 7 ...
0
votes
0answers
11 views

parent / child aggregate column

To start with, here is my fiddle. I have a parent / child relationship setup, I have them ordered by who they belong to, and I want to have a column called lastUpdated in which the parent has the ...
0
votes
0answers
15 views

SQL Server membership in asp.net [migrated]

I have inherited a asp.net 2.0 app that I have upgraded to 3.5. One of the odd things with this is is in the membership service it was set to use AspNetSqlMembershipProvider and it has an application ...
4
votes
1answer
48 views

SQL - Inverse Selection

I have two tables in my schema students(id text, matric text) attendance(id serial, a_date date, matric text references students matric) To get records showing date and student present, I can run ...
0
votes
0answers
28 views

How to move records to another database and free some space

We do monthly a "cleanup" of the database: we set the database in simple recovery mode and then we move records to an historic database so we can delete from the original for free some space with DBCC ...
0
votes
0answers
10 views

reorganize and UPDATE [duplicate]

This is my table called tickets with ID primary key ID-TicketID-TYPE 101-3-0 a02-1-0 01a-2-0 I wanted to UPDATE it and be like this ID-TicketID-TYPE a02-1-0 01a-2-0 101-3-0 but when I used the ...
2
votes
0answers
51 views

Log shipping and SIMPLE recovery mode

We have the need of implement the log shipping in our production environment, and we'll do this on the next weeks. In the other hand, we do monthly a "cleanup" of the database: we set the database in ...
0
votes
0answers
57 views

Why am I unable to use a temporary table more than once on my Stored Procedure?

I am using SQL Server 2008 to build a stored procedure. On it, I create a temporary table (#results) using recursion for getting all the ancestors given a specific record. My specific problem is, ...
0
votes
0answers
58 views

Query to match exact column or partial data of the column: SQL Server / Azure

Bit confused on how to get it work better than what has been done now. I am new, apologies if I'm asking for too much. I have trip details which have from and to locations stored in database from ...
0
votes
1answer
28 views

Errors importing data using COPY comand at postgresql 9.3.5

I am trying import a database table to Postgres 9.3.5 database server using COPY command as follows: COPY comment (generatedid, id, "timestamp", message, bugreport_id, personcontainer_id) FROM ...
0
votes
2answers
35 views

Joining 4 tables and selecting distinct values based on 3 timestamps

I have been trying to remove duplicates from my query results based on the time but I would need to consider 3 different times and i am not sure how to do that. As some of the testing happen multiple ...
0
votes
2answers
33 views

Match multiple components of a subquery CTE in PostgreSQL

I've got an app that grants access to users in varying different ways, and I'm attempting to write a query that determines access in all the different ways, but is readable, by breaking the access out ...
1
vote
0answers
14 views

Poor performance filtering mysql spatial join

First of all, sorry for the crossposting. I ask this question in stackoverflow and they sent me here I have a mysql table with spatial references (GEOGRAPHIC_FILTER), like cities, countries, natural ...
0
votes
1answer
85 views

How calculate the time difference between two consecutive rows

I have a table tickets with ticketid,owner, owndate columns. The table is as.. ticketid owner ownerdate 1001 LEWIS 2004-06-18 14:15:11 1001 WILSON 2004-06-18 14:16:54 ...
-1
votes
2answers
54 views

Getting all descendants of a parent

I have a table with two columns, Parent and Child. Need to get the list of all descendants associated with the parent records, Source Table +----+-----------+ | Parent | Child | +----+-----------+ | ...
0
votes
0answers
49 views

Centos 7, Postgresql Failed to Read Permission Data Directory in mounted Partition

I've a problem with start PostgreSQL 9.4 on Centos 7 Server. Because the partition /var/lib/pgsql/9.4/data/ (which contains PostgreSQL data) is full so I want to change to another partition. ...
1
vote
1answer
56 views

Keep Execution Plan in Cache - SQL Server 2012

How can I keep a query execution plan in SQL Server's cache and use it several times? When I execute a query for the first time it takes 7 seconds. After that it takes only 1 second. This query is ...