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

learn more… | top users | synonyms (1)

4
votes
3answers
192 views

SQL OrderBy When using an In() query

Example query SELECT * FROM Table WHERE ID in (5,3,4) How do I adjust this query so that the order of the returned entries follows the input of the ID's (IE, 5 first, 3 second, 4 third). Edit - To ...
2
votes
0answers
16 views

TLS 1.2 with SQL Server 2008 [duplicate]

I have a VM where I use SQL Server 2008 as a black-box data store for a product I work with. I'm being told by my IT police that my VM is not (or will not be) secure in a short time unless I can ...
5
votes
2answers
3k views

Does SQL Server have a Date_Format function?

All I found is a list of predefined DateFormat that I can choose from, like this As I remember in MySQL (and PostgeSQL too?) you can define your Date Format: DATE_FORMAT(now(),'&m_%Y') --for ...
0
votes
2answers
60 views

Two SQL servers for one website [closed]

I have a website that is deployed on an environment as follows: a load balance. two web server. two database servers. both of the two database server have the same structure and queries. I found ...
-1
votes
1answer
50 views

What is the optimized way to fill table values based on it's previous columns values and from other table column values?

CREATE TABLE TEST2 ( RowID INT IDENTITY(1,1), Ratio INT ) CREATE TABLE TEST ( RowID INT IDENTITY(1,1), Col1 INT, Col2 INT, Col3 INT ) Now, I want to insert values in table ...
1
vote
1answer
827 views

Replication Snapshot folder not cleaning up

The job that I thought was supposed to clean up old snapshots isn't removing the old files. The retention is left at default yet there are snapshots months old which remain. The job runs as the ...
2
votes
2answers
177 views

Limiting read access in postgres to few rows

We have a requirement where we want to limit the maximum no. of rows that a select query can return when its done using a particular login. So basically we would like to append a limit clause to any ...
0
votes
2answers
270 views

Dealing with data stored as arrays in a MySQL DB

So I know storing arrays in a DB field is wrong and would never do it myself, however a 3rd party plugin my company is using stores data in an array and I was wondering if you could help me try to ...
0
votes
1answer
188 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 ...
0
votes
1answer
41 views

Add ranking to query output

I'm new at programming with PHP/mySQL and I have got a little problem here. This is how my code looks like: SELECT COUNT(*) AS Number , Name FROM table GROUP BY Name ORDER BY Number DESC ...
1
vote
1answer
213 views

Select only rows that equal x but not x and y?

I'm having quite the challenge with selecting hierarchical data in MySQL although I feel the schema should be optimized for it since it's based on the WordPress database model. I've got 4 tables: ...
2
votes
2answers
163 views

Normalising Customers and Employers with a people table

At what normalisation stage is it recommend to split say Customers and Employees into a people table and then link to the unique attributes of Customers and Employees. I cant seem to find the ...
0
votes
1answer
307 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 ...
1
vote
1answer
52 views

Vertica performance on select from view with union

We have a huge number of rows(tens of millions), and for each table we have an associated view that is a select with UNION ALL between that table and several others. Now, we are doing a select from ...
6
votes
4answers
133 views

For SQL Server, how to fix simultaneous parallel table updates?

I have to update all records (add Guids) on two (indexed) empty columns of 150 tables, each table with around 50k records (using a script to create 40k updates at once in c# and post it to the server) ...
4
votes
1answer
124 views

Why do async_network_io wait types occur?

Last week something strange happened on our database. All of a sudden, the application blocked for our users who were not able to save new entities etc. After looking at the Activity Monitor of the ...
1
vote
3answers
230 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 ...
1
vote
1answer
47 views

Prepare MySQL for big UPDATE query on production server

Surprisingly I have not found anything relevant on this subject. What are best practices to prepare production MySQL server for a big update query? The question is broad but I'd like to know details ...
-1
votes
0answers
32 views

Get the sum of Total Churn_MTD(Current+2015+<2015) [duplicate]

how to declare 8 variables and get the total Sum,as you can see from the picture i created the 3 store procedures but dont know how to do the ...
0
votes
2answers
47 views

unable to connect to oracle in linux terminal in oracle VM ,TNS listner not connected

i installed oracle VM , new to oracle vm. Can some help me in connecting to oracle in Linux termial and TNS listner is not responding with IO failure on sql developer when pressing test button ...
4
votes
1answer
86 views

ORDER BY and comparison of mixed strings of letters and numbers

We need to do some reporting on values that are usually mixed strings of numbers and letters that need to be sorted 'naturally'. Things like, e.g. "P7B18" or "P12B3". @The strings will mostly be ...
1
vote
1answer
49 views

Displaying Distinct Max Value autonumber rows from tables in MySql [duplicate]

i am trying to execute the distinct records from mysql table having max value of it sno column. I have tried the following query but having no luck. SELECT DISTINCT p.sno AS sno, ...
0
votes
1answer
284 views

How to merge two databases, both with primary keys

I have two databases, both with the same tables, but the data is out of sync. I need to add data from database A to database B, but not overwrite any data in B that exists in A, instead add it with a ...
1
vote
1answer
12 views

getting records for yesterday day starting till ending PostgreSQL

Currently my application is running over 2 dbs one is snapshotDB one is evercamDB. In snapshotDB we are saving records now it want to retrieve them , currently am using this query select ...
1
vote
1answer
60 views

Select ONE most recent post for each author

I'm sure its a simple question and I suppose it was asked many times, but I just can't figure it out from other answers, sorry. I use recent versions of PostgreSQL and MySQL. I have 2 tables: CREATE ...
0
votes
1answer
120 views

Need help in incrementing the date in oracle

Error thrown as "Invalid number" while trying to increment the date. Given below is the query executed through sqlplus. Please help me on this. select ''''||to_date(:To_date, 'dd-mon-yyyy')+1||'''' ...
2
votes
1answer
55 views

SQL Query for Internal Messaging System

I'm creating an internal messaging system (No SMTP/POP3) and I'm looking for a way to query a user's list of messages. Here's my schema: Messages _MessageID (PK) _MessageParentID (if a reply this ...
0
votes
3answers
41 views

Incorrect syntax near ')' when executing multiple select statement

Incorrect syntax near ')' How do I execute only one select statement based on user input i.e @id. Here is my syntax. Create Procedure employee @id int, @year int AS SELECT CASE WHEN @id = 1 THEN ...
-2
votes
1answer
44 views

Extract ID String - PostgreSQL 9.2 [closed]

I've got this directory path: /userfiles/account/5554/attachment/26687981/file/2790000/main.with_name/photo.jpg /userfiles/account/(accountid)/(filecontext)/(ownerid)/(variation)/(filename) -- ...
2
votes
2answers
280 views

How can I count all children & grandchildren until the 7th level?

I have 3 tables right now 1. members 2. members_parents 3. members_status How can i count the children & grandchildren until to the depth level and separate the count() for the status 0 = ...
1
vote
3answers
61 views

Retrieving the top row of data

I have very limited SQL knowledge and need to report on the top most current row of data within a table. The table holds Effective Date, Information and a Renewal Date. select DATA_KEY_ID, ...
2
votes
2answers
39 views

Select ID from costumers that do not have contacts last 7 days and 2 times in the month

I have 2 tables: custumer, c_contact. c_contact is all the e-mails I send to my custumers. From now on I need to put a new rule that the costumer can't receive a new e-mail if: 1) It received an ...
-1
votes
1answer
75 views

Group when there are multiple items by a particular user within a certain timeframe [closed]

SELECT * FROM ( SELECT articles.id, articles.author_id, users.username, COUNT(articles.id) AS number_of_articles, GROUP_CONCAT(DISTINCT articles.id) AS articles_published FROM articles ...
0
votes
0answers
17 views

RDS Large SQL Server Instance high cpu low connections?

We are routinely getting high CPU usage with only 12 connections on our M3.large instance. I'm not particularly skilled with AWS RDS, please forgive any ignorance or obvious mistakes. But I don't ...
6
votes
2answers
423 views

Help with this query

I have a person table. I also have a car table and books table. The car and book table both have a foreign key back person. I am trying to count the number of books and cars each person has: I try: ...
0
votes
1answer
31 views

SQL Server Alerts (notify operator when job failed)

I setup database mail, created an operator today and enable notify operator when job failed. Is that all or do I need to create an alert too? My boss just needs emails if any job failed. Also how ...
3
votes
2answers
48 views

Unable to create stored procedure to access excel files in SQL Server?

I need to create a stored procedure to access Excel files in SQL Server. I have created the below stored procedure. Since I am a sysadmin, the stored procedure is working fine for me. But for the ...
-2
votes
0answers
42 views

Data file NDF Vs MDF and performance overhead

We have database with multiple data files (*.ndf) and one of the data files we made to have static data tables i.e. not a transnational data (LibraryPrimary.ndf). Here is the load test result with ...
1
vote
1answer
52 views

Combining two queries

I am trying to write code for this query: Find the names of the actors that played at least in one movie since 2000 and where not directors of any movie at this period of time. My thought was to ...
2
votes
1answer
1k views

Slow Performance of Parametrized Query in Excel due to Parameter Datatype

I'm pulling Data from a SQL Server 2008 into Excel using a Parametrized ODBC Query created by the Excel Wizard. (Data-->getExternalData/FromOtherSources-->FromDataConnectionWizard-->ODBC DSN) My ...
1
vote
1answer
62 views

How to correct this oracle error?

This query SELECT praogrupos0_.ID_GRUPO_SEDE "ID1_209_", praogrupos0_.ID_EJERCICIO "ID6_209_", praogrupos0_.ID_INSTITUCION_LIQUIDADORA "ID7_209_", praogrupos0_.ID_PERIODO "ID8_209_", ...
-3
votes
3answers
129 views

Finding the most common genre for “eMovies”

Given database of the website "eMovies" that manage data about cinema movies. Write in SQL query the most common genre (that have the biggest number of movies) The tables: Actors ActorID ...
-5
votes
2answers
106 views

Query that finds the names of the directors that played in movies that they directed

Given database of the website "eMovies" that manage data about cinema movies. Write in SQL query that finds the names of the directors that played in movies that they directed The tables: ...
2
votes
5answers
20k views

Retrieving row count without using Count function

I wrote a query below which shoots me a syntax error why would it do so, SELECT MAX('Row') FROM (SELECT ROW_NUMBER() OVER(ORDER BY ID DESC) 'Row' FROM USERS) Error Desc: Incorrect syntax near ...
4
votes
1answer
187 views

Reporting on a normalized Key-Value pivot

ERD & SQL Fiddle provided. We're trying to design a reporting tool for our stakeholders around a normalized Key-Value Pair model. We've tried to find a solution using Pivot Tables but can't seem ...
1
vote
1answer
48 views

INNER JOIN for 3 tables [duplicate]

I am doing a small course in SQL during my academic degree, I am very new with this material. I saw Inner joinning 3 tables on StackOverflow, I tried to do INNER JOIN between my three tables, the ...
3
votes
2answers
322 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 ...
3
votes
1answer
11k views

Joining 3 tables using SQL Query?

I'm having problems joining three tables. It works well when I use the same query for joining two tables (after removing LEFT OUTER JOIN C ON B.No = C.No). However, it doesn't work when I use three ...
0
votes
1answer
76 views

How do I write this query?

I have a table that looks like this: CREATE TABLE `message` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `grp_id` int(10) unsigned NOT NULL, ...
1
vote
1answer
217 views

Query multiple rooms with different conditionals (Adults, Children)

I have a simple query where I select available x Rooms with x Adults + x Children per hotel that matches a date range, but I'm having a hard time trying to figure out how to query a list of rooms per ...