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
14 views

Can I reset a connection to its default in Oracle's SQL Developer?

I've never used SQL Developer, but I've had to use if for my placement. I've been tasked with setting up the database locally however I've made a mistake somewhere and it's now not letting me delete ...
1
vote
1answer
45 views

Matching data in two tables

I'm teaching myself SQL and I ran into a question that may be related to joining tables. I'm just a bit unsure. Say, you had two tables, one listing a customer's creditcard_number, and one listing ...
0
votes
1answer
12 views

MySQL get previous record and compare

Need to make a Comparable between the records of this table and take the total times the value calledstationid 42 preceded the value 34 (this is a system log table and calledstationid is not an ...
-4
votes
1answer
39 views

How does Oracle handle types in this UNION query? [on hold]

SELECT 1 FROM DUAL UNION SELECT '2' FROM DUAL; what does this give? knowing dual is default table and is a single row table.
1
vote
2answers
38 views

Noob questions on tables in a sql model

I'm a noob when it comes to SQL or PHP and I'm a creating a rather simple car-sharing web site. The user can engage a trip someone created and can himself create a trip. Now I'm currently designing ...
3
votes
1answer
3k views

Difference between now() and current_timestamp

In PostgreSQL, I use the now() and current_timestamp function and I see no difference: # SELECT now(), current_timestamp; now | now ...
1
vote
1answer
56 views

Scramble the data output of a stored procedure

I have a stored procedure that produces data for a call center system every morning. However, the data is sent in the same order daily. Is there a way to send the day in a different order every day ...
1
vote
2answers
56 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 ...
0
votes
1answer
6 views

How to use a value from insert in conditional insert in postgres

insert into addresses(street, city, user_id) select 'street1','LA', 2 where exists (select * from users where users.id = $$$$$ AND users.storeaddress='true')) I want to insert address for a ...
0
votes
1answer
26 views

SQL Server 2012 - Can't detach database on mirror server

I'm running SQL Server 2012 in a mirror configuration and I need to move the mirror's transaction files. I deleted the mirror setup on the primary but I can't detach the databases on the mirror, the ...
-3
votes
0answers
24 views

database is not getting restored second time with this query [on hold]

USE master GO ALTER DATABASE Tfs_CoeTest SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO RESTORE DATABASE Tfs_CoeTest FROM DISK = 'D:\Backup123\Tfs_CoeTest' WITH MOVE 'Tfs_CoeTest' TO ...
0
votes
0answers
16 views

Line terminators \r and \n

As i am working on this project i have couple of questions about line terminators and how to know which one to use when. 1) when i load data into two tables using just "\r", all desired data is ...
1
vote
1answer
90 views

Querying sums of grouped consecutive rows in PostgreSQL 9

I have data about people traveling in different countries like this: country | begintimestamp | distance Germany | 2015-01-01 00:00:00 | 100 Germany | 2015-01-01 01:12:13 | 30 France | ...
1
vote
2answers
2k views

Strange behaviour of a query with order by and rownum on Oracle's Exadata server

I am executing the following query on two different database servers: SELECT start_date, end_date, resort_id FROM employee_activity WHERE employee_id = 27 AND start_date < ...
0
votes
1answer
21 views

Slow query - just error count

I deal with slow queries in whole project. I indexed heavily but the results are nowhere. I had a lot of logs (thousands per minute) from SCADA systems and I am trying to count them for each SCADA ...
4
votes
1answer
30 views

Calculating daily growth using previous row value in new column - SQL Server

I have the following query below that shows size of a database and when this data was collected. I am trying to create a new column that has "average daily growth" which would be determined by the ...
3
votes
2answers
58 views

Query to calculate database growth

I have the following query that outputs some good information from MDW data collectors regarding database space usage. I am wondering with the following columns (db size, reserved space, unused space, ...
0
votes
1answer
42 views

Artificially increasing query time

Very weird question: Is there any way to artificially inflate the amount of time a query will take? An infinite loop would be great. SELECT CLAIM.UNIT_PRICE FROM CLAIM WHERE ...
-2
votes
0answers
41 views

SQL Server 2014 - Query output

To be clear: I want to use the result of first query in the second query. Below are the two queries: Query 1 select files.originalfilename from files inner join digitalfiles on files.fileid ...
2
votes
1answer
27 views

Oracle: REGEXP_LIKE: Strings with angle brackets aren't found (whether they are escaped or not)

The following question will answer my original question, plus many others. What would the correct syntax be to do a REGEXP_LIKE search (in Oracle Database 12c) for this string (which exists somewhere ...
0
votes
1answer
212 views

Select Query takes more than a minute to retrieve data

I have a table that has 99 columns, all of them are not needed but they were there when we started. There is a Primary Key (Objectuid) which is a GUI and has the Clustered Index on the PK. The Table ...
3
votes
1answer
46 views

identify gaps and islands

I have a database that has the following structure +---------------------+------------+---------------+ | timestamp | EngOilP_sd | CompOilLVL_sd | ...
3
votes
2answers
48 views

Computed Column Update when Table Value changes

I have environmental sensors collecting some raw data from environmental stations. In addition to the sensors, there is a physical gauge measuring water height (staff gauge). I'm trying to set up the ...
2
votes
1answer
308 views

How to include concatenated values in a dynamic pivot column value?

I am extending a dynamic pivot query. The original query works fine. In the second query, instead of displaying the date as a value for the pivot column, I would like to display a concatenated column. ...
4
votes
0answers
34 views

Correct the query in a redundance database

I have 2 tables: Posts, PostMeta: Posts: ID | Posttitle | postexcerpt | posttype | postcontent 1 | Title | ASD | post | ASDASDASD 2 | Title | ASD | ...
2
votes
1answer
36 views

Case When over 2 columns return results into 1 output column

I have an issue in SQL Server (using 2014 but not sure that's relevant). I have 2 variables Q20 and Q46 which depending on result I want to output a value to the same column for each result. For ...
14
votes
4answers
2k views

Why should a key be made explicit?

I am very new to the subject of databases so this may sound ignorant, but I am curious why a key should be made explicit within a table. Is this primarily to tell the user that the given column value ...
-3
votes
0answers
18 views

duplicates of part.num to be summed and add another column called user [on hold]

There are 3 columns part num, Qty and MO. Each MO has part numbers.So there might be same part numbers in MO's. Each part num has qty. So, if I group by part num, I get Qty. 1.There are duplicates of ...
4
votes
1answer
97 views

Find clients who bought more than 1 million units in 3 consecutive months

I want to find the client's code (cCode), who bought more than 1 million units, in three consecutive months. Here is my data: gDate cCode buy 2014-10-22 15108164 1653410 2014-12-22 ...
2
votes
1answer
789 views

DELETE from Linked Server table using OPENQUERY and dynamic criteria

I'm attempting to run a DELETE statement from my local SQL Server to delete appropriate records from a table in my remote linked server using OPENQUERY(). I'm using the following code, but it seems ...
5
votes
4answers
140 views

check when last backup was taken

Brent Ozar had an interesing newsletter on 2015-06-22; How do you manage dbas measuring backups, where he thinks that a good DBA should check when the last backup was done it was last restored ...
-1
votes
5answers
58 views

How to apply two different where conditions for two different tables in same select statement

select a.column1, b.column2, d.column3, d.column4, d.column5, d.column6 from table1 a left join table2 b on a.colx = b.coly left join table3 c on a.colx = c.colz left join table4 d ...
1
vote
0answers
17 views

Looking for a DR-like solution to enable full data warehouse re-load while having secondary copy live

I am looking for suggestions/ideas to the following problem. We have a number of data warehouses for each of our clients (on SQL Server 2014). These data warehouses are maintained fairly fresh with ...
4
votes
1answer
3k views

“No row was updated error” in SQL 2012 - worked fine in SQL 2005 and 2008 [on hold]

I have a database in SQL Server 2005. We are currently looking at upgrading to SQL Server 2012. I installed SQL Server 2012 in a test environment (Windows Server 2012 virtual machine). Backed up ...
1
vote
2answers
475 views

After Restore Log_reuse_wait_desc of Replication

I'm wondering if anybody has ran into this issue before and has any suggestions on what's causing it/how to fix it. We are restoring a database into lower Dev environments and after the restore the ...
0
votes
1answer
28 views

A form including content from two tables

I am working to create a database of all the places or administrative entities of one country. Most work will be about adding new districts. I have to detail which region every district belongs to. ...
0
votes
1answer
52 views

SQL Server 2012 Exclude a value

I'm teaching myself SQL, and I ran into a scenario that I cannot seem to solve. Please any help. I have a table called tblRecord with a column called BuyerID, in this case there are two BuyerIDS, and ...
-3
votes
0answers
52 views

i want get all left and right user with all details [on hold]

Sample data: CREATE TABLE [dbo].[binaryUser] ( [id] [int] IDENTITY(1,1) NOT NULL, [joiningDate] [date] NULL, [placement] [varchar](100) NULL, [pId] [int] NOT NULL, [cId] [int] NOT ...
5
votes
2answers
62 views

Using Left or substring with wildcard in SQL

I am looking to retrieve information from a field, but am having troubles getting exactly what I want. The information I want has no set order and I am also looking for two different things. Here is ...
0
votes
0answers
16 views

Using pipelined order by while fetching only first ten rows

PostgreSQL 9.2 I have the table table: id user_id amount PK integer integer and I need to fetch the first 10 rows as follows: SELECT user_id, SUM(amount) s FROM table GROUP BY ...
0
votes
1answer
145 views

How to perform same DML statements on two different servers (Oracle and SQL-Server) simultaneously

I have two servers, Oracle and SQL-Server. I have same database on both the servers. I want to perform DML (insert,update,delete). How can I perform same DML statements on both the servers ...
4
votes
0answers
51 views

Find Shoe Size Selection

I'm developing a feature that allows users to input their foot dimensions and have the proper shoe size returned to them. I'm having difficulty deciding on the best way to implement this feature. The ...
0
votes
2answers
100 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 ...
6
votes
4answers
317 views

Store millions of rows of denomalized data or some SQL magic?

My DBA experience doesn't go much further than simple storage + retrieval of CMS style data - so this may be a silly question, I don't know! I have a problem whereby I need to lookup or calculate ...
2
votes
0answers
131 views

Sync a local MySQL database and a live server MySQL database

I want to store data in my local MySQL database and after a time interval or when system connected to internet it will update my live MySQL database remotely. Is it possible? I have an inventory ...
4
votes
1answer
70 views

Better database design

I'm using a MySQL database to store data from my java application. In java I have two classes: The VocabularyList class has a name and holds a list of vocabularies. A Vocabulary has a vocabulary ...
2
votes
1answer
102 views

SQL Server 2012 - Dropping Snapshots takes hours

We recently did a SQL Server upgrade from 2005 to 2012. We have a nightly job that drops a snapshot of an active database. The snapshots gets created again later in the day. Before upgrading, in SQL ...
5
votes
2answers
80 views

Combining data from multiple rows

I am relatively new when working with queries so let me apologize in advance. This is a MS 2012 Server that I will be working with. This data has been brought into a staging table through a nightly ...
3
votes
1answer
66 views

SQL Joins and Relationships

I am confused by joins. I want to know how to choose the join based on the relationship between tables, or do joins have no dependency on relationship? if relationship is "one-to-one" then "Inner ...
3
votes
1answer
111 views

Query looks optimal but logical reads is huge

I run the following (really simple) query in SQL Server: SELECT MAX(PK_Field1) FROM MainTable kh WHERE kh.PK_Field1 >= '2014-12-01T00:00:00' AND kh.PK_Field2 = 1572 AND ...