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

MYSQL - deleted rows without permission

I have a problem involving MySQL. I had about 3000 records in a table and today most of them disappeared. Today I have 1000 records left. I didn't do anything. Is there an explanation? A MySQL error ...
0
votes
1answer
29 views

SQL Syntax Error - Unsure if it is empty value or backslash

I am getting a syntax error when the following query is being run:- INSERT INTO mw_reward_point_order VALUES(9477,0,0,144,,'100/1') I originally thought it was because there was an empty value ...
0
votes
1answer
50 views

Windows cluster failed over, but SQL instances didn't move

I recently inherited a SQL Cluster (2008R2) which for the most part behaves itself impeccably. The windows cluster is made up of two nodes running Active/Passive, Node1 and Node2 are dedicated ...
0
votes
1answer
23 views

Find all stats that were sampled

I am using Ola's scripts for stats updates and for one particular index I want to do full scans when updating stats (to solve for the Ascending Key problem in conjunction with trace flag 2389). We ...
1
vote
1answer
66 views

Combining 2 SQL queries

I have these 2 queries below that I use to calculate net profits from Jan to Dec. Query 1 /* Profit for the Period 13 */ SELECT * FROM ( SELECT MONTH(T0.RefDate) AS Month, '311999' AS 'SAP Code', ...
0
votes
2answers
51 views

How to get data everyday's eight AM.?

MySQL database, I have a table which contains some column. First column is datatime type, like "2016-03-01 08:00:00", "2016-03-02 08:00:00". What should i do to get everyday's 8 AM. from this table? ...
12
votes
2answers
547 views

How can SQL Delete using a sub query

The following code was added by one of our developers to delete duplicate records from the table: DELETE SubQuery FROM ( SELECT ID ,FK1 ,FK2 ...
0
votes
2answers
61 views

How would I select distinct records from the same table on two different databases?

I have two different databases that both contain a table with the same structure. I have to go across and select the distinct records across both, how is this best achieved? The uniqueness is based on ...
0
votes
1answer
31 views

How to download or place a copy of original tables with locked-permissions via remote connection in Oracle SQL Developer?

N00b question here: I'm still learning Oracle SQL Developer. Although I understand how to query databases/tables remotely, I'm unable to manipulate the data due to permissions-basically I would like ...
0
votes
1answer
185 views

MySQL code to show specific rows based on another…?

I'm having a hard time figuring out how to do this, and I can't explain it well. Since I don’t know how to explain it I can’t seem to locate an answer online by simple research. So, I have to draw it ...
0
votes
1answer
36 views

MySQL Explain gives different result for same query, query performance changes

I've been having some performance issues on my production server. The main issue, I think is the table pricelist_entries, which has approximately 6 million rows. Basically its holds all of the ...
0
votes
0answers
28 views

Getting the most recent date in a table with good performance?

I have been monitoring my server and have noticed a few slow queries. One is getting the most recent date in a table with about 2691225 records. I am using the following: SELECT dt FROM dly WHERE dt ...
0
votes
1answer
35 views

How to store Alternate Names for Places or City in Table

What is best way to store Alternate Names of the Places (City or Locality) in MySQL database columns which user will be searching? Examples: In India user may search for "Chennai" or "Madras" and ...
1
vote
1answer
61 views

SSAS Hierachies duplicates when browsing

The dimensions in the cube are giving us duplicates, there is no error while processing the cube, but when the cube is browsed we could see duplicates. There is a hierarchy in our dimension, the ...
0
votes
3answers
41 views

Is it possible to make an Update query right after Insert returned new Id's

I am using MS Sql Server 2008R2. For example I need to insert many rows inside TableA and I want to make an Update another TableB with newly inserted Ids from TableA. Is it possible to do in one SQL ...
2
votes
2answers
80 views

How to optimize this crazy SQL Query (Specific)

In short, I have this SQLite3 query that uses up 30% of CPU when being run. SELECT s.* ,r.RaagEnglish ,( SELECT w.WriterEnglish FROM Writer w WHERE w.WriterID = ( ...
2
votes
0answers
40 views

ERD to SQL Server

I am working on an assignment and am having one heck of a time getting my head wrapped around these questions. I need to be able to write in SQL Server 2014 certain select statements based solely off ...
-5
votes
1answer
34 views

how to data dictionary? [closed]

How to data dictionary owner and table name. Additionally, the output should add the comments on the rows. Input: owner and table name. Output: columns for Name, Null?, Type, Comments focusing on a ...
1
vote
3answers
68 views

Display two digits after decimal point in SQL from average value

This is my code SELECT AVG(`page_rate` ) FROM `pages` INNER JOIN `languages` ON `pages`.`lang_id`=`languages`.`id` WHERE `abbr` IN ("EN-UK", "EN-US", "EN-AU") How can I display only 2 digits ...
3
votes
3answers
268 views

Listing rows with a WHERE condition

I am struggling with a SQL query that lists hosts that are offline. Problem The problem occurs when I need to list hosts that don't have any ports open (status = 0), so looking at the table at the ...
0
votes
2answers
42 views

How to get when MySQL instance went down last

Is it possible to determine when a MySQL instance went down last? Is there a log file or literally anything at all that logs the server status in MySQL? I have trolled through countless articles ...
3
votes
2answers
256 views

How to get difference in value over 15min interval?

I have this table: The 2 important columns here are domainid and Soldtickets. Soldtickets show how many tickets were sold today. I make a call to my server and it tells me that I made the call ...
1
vote
1answer
20 views

Select row from non-empty node value in xml column using xml query

I am trying to select the rows from the table by putting the condition on the xml column. The condition like if there is date value on the node ‘Completedon’ in the xml column then select that row. ...
2
votes
1answer
45 views

Iterative SQL Delete Statement

The following is a simple version of a delete I need to perform. delete from table_name where order_date < (getdate()-60) go This is deleting a large number of blobs and to clean up the table I ...
1
vote
1answer
33 views

Difference between Generate Script option at database level and backup and restore option

When doing that generate scripts on the database level what difference does it do from doing a backup and restore on the database? It seems to me that they both provide the same purpose. What would be ...
0
votes
1answer
28 views

Oracle : Is my DISTINCT function working properly?

I have alphanumeric values as my primary key. I am querying my database in two different ways and finding different results. It is almost certain that I might be missing some key point in my queries. ...
0
votes
0answers
17 views

How to find out user activity for calls made from an application server?

I have to log user activity on the SQL server for the calls made from SAP application server, the problem is the Application server does not send any User information along with each call and uses a ...
0
votes
0answers
30 views

Group by periods in SQL

Each register is an event in a location with an id, but events take place "in clusters" (e.g zero to two events every day from 31/02/2014 to 10/03/2014, all with the same id). I need to detect the ...
2
votes
1answer
37 views

Stored procedure unable to compare

Hi I tried implementing the below stored procedure which always takes my if condition as true and implements . CREATE DEFINER=`root`@`localhost` PROCEDURE `InsertOpen`(in uid varchar(11),in S_ID ...
2
votes
1answer
61 views

How to automatically fix Orphaned Users with PowerShell and SQLCMD

I'm trying to properly capture output from SQLCMD in SQL Server 2012. Here is the PS script: $dbname = "MyDB" $InstanceTarget = "localhost\SQLEXPRESS" $FixOrphansSQL=@" WITH login_CTE (name, type, ...
1
vote
1answer
59 views

Select column values linked to exact set of values in another column

Given the below chats_users table in Postgres 9.5, with integer columns chat_id and user_id, I want to find the chat_id associated with an exact set of user_ids, for example: user_id IN (1, 3) => ...
0
votes
1answer
51 views

How to get top 5 rows of given Id? [duplicate]

I have the following code: DECLARE @Latest TABLE ( DomainId bigint, [date] datetime2 ) DECLARE @Rows int DECLARE @History int INSERT INTO @Latest (DomainId, date) SELECT DomainId, ...
0
votes
0answers
9 views

exporting selective data to excel in php

I have a table called tbl_order which has three columns: credit_card debit_card selected_payment_method i want to export to excel value of column 1 or 2 only depending upon the selected payment ...
0
votes
0answers
11 views

dba_tab_partitions we have all columns except MAXVALUE column

i want to cross check all partitions were created properly or not according to the timestamp, TO_DATE(' 2013-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', is there any way to cross check partitions??? ...
0
votes
1answer
28 views

What is DBCC66 and DBCC63 files

Tried to get some clarity but can't find any thing googling or searching in forums. We got a couple of files in the Data folder of one of our MS SQL servers databasename.ndf_MSSQL_DBCC66 ...
-1
votes
2answers
57 views

Count txn date in oracle database [closed]

We want to count transaction date/time as result screenshot above, Please helps check code as below, and the code as below is when run the result as screenshot below, Thanks all guy. for r ...
0
votes
1answer
31 views

Restoring multiple snapshots with SQL Server 2008

I noticed I cannot have multiple snapshots of a SQL Server database and then restore from one of them (without I believe, deleting all but the one I want to restore). Is there a way to keep multiple ...
0
votes
3answers
29 views

Aggregate and GROUP BY conflict with HAVING?

I don't know if my logic in my query is incorrect, or if I simply have a syntax error, or both. For each customer that had more than two orders, I want to list the customerID and the total number of ...
0
votes
0answers
46 views

Error 1129: Host '' blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

When I run a python code which connects to mysql, I see this error; "Error 1129: Host '' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'". Here is what I have ...
1
vote
1answer
48 views

Aggregate sampler function for programmer express predictions

Are there any SQL-standard or DBMS implementation that offers "sample aggregator" for predictably repeated columns? I will explain, see bold text at the end. PS: this question is about "little ...
1
vote
1answer
36 views

Deleting aged postgresql rows with tricky condition

I have two postgresql tables I need to clean up as part of maintenance. The tables, as described in my Django front-end, are: class Group(models.Model): owner = models.ForeignKey(User) unique ...
1
vote
0answers
90 views

How to convert .ibd files to .sql [closed]

Could any one please tell how to convert .ibd , .frm, .MYD, .MYI FILES TO .SQL . Or is there any way to open this files in php my admin .. Please tell how to convert this to .sql file
0
votes
1answer
50 views

Not exists in sql query

I'm using oracle database I need to display customer id and customer name of those customers who have not purchased at all from any retail outlet using not exists My query: select ...
3
votes
2answers
83 views

Database model about libraries

I need to make database model about libraries. In that model I'm tracking more libraries and every library has it's own moderators. Every moderator can make categories of the books and than add books ...
0
votes
1answer
30 views

Select records not associated to a specific tag in a many-to-many relation

as shown in this sql-fiddle I have a bridge table events_tags representing a many-to-many between events and tags. I need the fastest way to find all events not associated to a given tag t. The ...
3
votes
2answers
50 views

IN Clause - listing values VS query

My app runs a lot of queries like this SELECT ... FROM Table WHERE CategoryID IN (SELECT CategoryID FROM OtherTable WHERE ..) To save performance I decided to cache the second subquery in the ...
3
votes
1answer
67 views

Can this SQL Query be improved

Related to one of my previous questions: How to select a subset from a query result I now have this Query: CREATE TABLE #JourneyLogs ( JourneyStartId INT, JourneyEndId INT, ...
1
vote
1answer
32 views

How do i insert a value into table2 from a trigger on table1

i have 2 tables with a column name WHO, and im using these 2 tables to create a view. where FSwho.who = FStasks.who if i enter a new record into FStasks where FStasks.who = LIZ, but theres no record ...
3
votes
2answers
62 views

PostgreSQL: Generate a series of dates for each group in a table

I have a balances table in PostgreSQL 9.3 that looks like this: CREATE TABLE balances ( user_id INT , balance INT , as_of_date DATE ); INSERT INTO balances (user_id, balance, as_of_date) VALUES ...
4
votes
2answers
156 views

Is there a way to SELECT n ON (like DISTINCT ON, but more than one of each)

I have a table us_customers that looks like this (with hundreds of thousands of rows): +----------+----------+ | id | us_state | +----------+----------+ | 12345678 | MA | | 23456781 | AL ...