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

SYNTAX ERROR: delete from multiple tables with inner join

Sorry, but I need syntax help :( This needs to run on SQL Server 2005 + DELETE SO, ASO, ASOV, AOV FROM SYS_OPTION SO INNER JOIN ADM_SYS_OPTION ASO on SO.OPTION_ID = ASO.OPTION_ID INNER JOIN ...
-1
votes
1answer
64 views

A complex query to Joining 2 tables and getting result [closed]

I have a database in MySQL. I have 2 tables, Structures as follows : t1 t2 I want to join both the tables and result should be like this : Employee_id | count(DNIS) | total_calls | count(DNIS) ...
3
votes
1answer
431 views

Benefits of SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

I use SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED in the majority of my general SQL queries, mainly because this was drilled in to me when originally learning the language. From my ...
2
votes
1answer
68 views

Multiple indices on a table

I have run SQL Profiler and I can see that I'm "missing" some indexes (non-clustered) on a table. How is it best to handle indexes that can be a "subset" of another index? Index 1 UserId, ...
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 ...
1
vote
2answers
75 views

How to break down RELATIONAL data into HIERARCHY data structure?

I have a query that returns the following dataset: RELATIONid MAPid D1id D2id D3id 4999 4999 626 1250 7 5000 5000 626 1250 8 For the next step, I need to bind those ...
0
votes
1answer
66 views

Select all from table using procedure oracle

I am trying to execute the select command in a procedure.Initially i retrived all of the columns of the table in the procedure using cursor. The real problem comes when I am trying to access the ...
5
votes
2answers
31 views

Combine two event tables for multiple timelines into a single result set

This question is an extension to a question I've previously asked that was overly simplified. The more accurate example is demonstrated in this SQLFiddle, where I demonstrate a working (but slow) ...
3
votes
1answer
69 views

Slow window function query with big table

I'm doing some performance testing on a new DB design on PostgreSQL 9.4rc1 and I'm seeing some pretty slow queries using window functions. Here is my table setup: CREATE TABLE player_stat ( ...
0
votes
1answer
11 views

MySQL NDBcluster 7.3 limitation on Table Joining in a single SQL statement

I am a novice user of Mysql database and recently my company is evaluating MySQL Cluster for its shared nothing architecture and synchronised replication. However my colleagues informed me that the ...
2
votes
1answer
92 views

Update one column based on count of records of grouped value in another column

Given a table CREATE TABLE TABLE_ITEMS ( serial_num int null, item_group int null ); INSERT INTO TABLE_ITEMS VALUES (0,1), (1,1), (2,1), (3,1), (4,1), (0,2), (1,2), (2,2), (3,2), (4,2), ...
0
votes
0answers
54 views

Buffer too small for CLOB to CHAR or BLOB to RAW

I am trying to select a clob from database to put it in a jasper report. The query is: <queryString language="SQL"> <![CDATA[ select to_char(PLAN_DESCRIPTION) as PLAN_DESCRIPTION ...
2
votes
1answer
31 views

Local SSMS client is not connecting one particular server

My SSMS is not connecting to one particular server say X except X it is connecting to all the other servers. Could not find the root cause for this problem do any one have idea here? Guy sitting next ...
3
votes
1answer
81 views

Replace NULL with empty string [closed]

Due to precedence set within my organization, I need to replace NULL values in certain columns (roughly 15-20) with the empty string. While the solution comes quite easily in more traditional ...
0
votes
1answer
48 views

How would I grant select on a table being used in a different database to a user role in SQL?

I have a view that's selecting rows from a table on a different database. When calling this view from my application I get an inner exception thrown saying the application user is not able to access ...
1
vote
1answer
19 views

Named Parameter Markers in DB2 for z/OS

I have a query where I will be using the same value twice for one of the parameters. This query will be run under IBM Data Studio to see the results. Below is a sample query: SELECT * FROM ...
3
votes
2answers
208 views

What is the difference between Used and Allocated space?

I am learning Database operations and I have found a couple of resources online that have given me a loose understanding, but I still couldn't explain the difference myself. Explain like I am five ...
1
vote
0answers
26 views

ANY in postgresql gives weird error

when I do: SELECT ARRAY[4] I get array integer[] ------ {4} and if I do: select * from b where b.ID = ANY (array [4]) That works. Now, something else: select array_agg(4) I get: ...
1
vote
1answer
46 views

How can I improve this query in PostgreSQL?

I've been using PostgreSQL for a little over a year. I am continually whacked by queries that have counts in them, such as: SELECT COUNT(*) AS count_all, listings.id AS listings_id FROM "listings" ...
1
vote
1answer
34 views

Postgres - window function rank and count

I have some tables that track athletes time around a track: competitions, competition_users and competition_user_sessions I am constructing a query that extracts the current rank and total no of ...
1
vote
1answer
36 views

Update query could not be bound

I'm trying to do a simple update query and I'm getting this error: The multi part identifier "customers.customer_name" could not be bound Query: Update Suppliers Set City = (select s.city ...
1
vote
2answers
27 views

Custom ORDER BY

Are there other ways to use ORDER on my results? 20150507094958A DISPOSED 2015-05-07 09:50:00.853 Samuel MONEY 20150507094958A DISPOSED 2015-05-22 09:25:00.000 Jeff AUTOMOBILES ...
1
vote
4answers
53 views

Grouping Data Using Joined Tables with Certain Distinct Values

I am struggling to get my head around how to do this so please bare with me while I explain. We have an order system which records orders, order lines, items, users etc. What I am interested in in ...
1
vote
2answers
26 views

Query not recognize alias [duplicate]

I have the following query, the alias it's called DELAY, works fine, but when I try to run the first query adding AND DELAY < 0, the alias is not recognized. I tried to create the alias QUERY AS ...
2
votes
1answer
328 views

How do I import XML to a SQL Server table?

Can anyone help me work towards fixing my solution to import my XML data into a SQL Server Table? I have done my research, but this task has been very hard for me to accomplish. Everything I have ...
1
vote
1answer
47 views

How to do a SELECT inside of a PIVOT

I am trying to SELECT values from a column in my database in order to perform a PIVOT on those values without hard-coding them. SELECT * FROM (SELECT ItemType, [Status] FROM ...
1
vote
0answers
19 views

Create new server in SQL Server instance [closed]

In our office we have two servers (development and Test). I need to create a new server for practice purpose. How can do it?
0
votes
2answers
49 views

How to optimize a large join to create a WHERE IN

The following sqlite database query takes about 40 seconds on my Core i7. SELECT t.a FROM titles t WHERE t.a IN ( SELECT e.id FROM erpubtbl e JOIN abstract_mesh am ON am.pmid = e.pmid ...
0
votes
1answer
51 views

How to print to console in SQL?

I'm using PostgreSQL And I want to print a message to the console. If I use plpythonu I use plpy.notice If I use plpgsql I use raise notice but how do I print when the function is pure SQL? using ...
2
votes
1answer
28 views

Pivots giving too many results

I'm trying to learn how this pivot thing works. I don't think I'm understanding it quite right. I just want to do a simple count for a bunch of item types that have some statuses. The table I'm ...
4
votes
2answers
127 views

Postgres 9.4.4 query takes forever

We're running Postgres 9.4.4 on CentOS 6.5 and have a SELECT query that has worked for years, but stopped working and hangs after we upgraded from 9.2 (it took a while to notice it, so I don't know if ...
1
vote
1answer
36 views

Last accessed timestamp of a Netezza table?

Does anyone know of a query that gives me details on the last time a Netezza table was accessed for any of the operations (select, insert or update) ? Thanks
0
votes
0answers
25 views

Troubleshooting Memory-Pressure on SQL Server with 80+Gb RAM

I have a SQL Server cluster with 80+Gb of RAM and multiple production enterprise databases and applications running. We are encountering memory-pressure errors and are trying to troubleshoot what's ...
1
vote
2answers
64 views

SQL - Select Rows in a Certain Order

I'm new here - if I missed anything in the question please let me know. I'm trying to build a people directory like LinkedIn has: http://www.linkedin.com/directory/people-a I don't want to fetch ...
-3
votes
1answer
48 views

SQL Server questions (for masters) [closed]

How to rename sa to new_sa in SQL Server 2000? How to do and what is the impact SA rename impact in SQL Server 2005, 2008, 2008R2, 2012, 2014, Express Edition How to recreate sa login if deleted How ...
1
vote
1answer
24 views

Update reps table with right values in a trigger after insert on userterritory

I two DBs veeva and pdone as shown below in the pics As you can see veeva is simple and hasn't no constraints which relies on duplicate and wrong values. The problem happen exactly on ...
1
vote
1answer
35 views

how to avoid duplicate record with certain conditon

Heading ##I have a table with data like below +----+--------+-----------+----------------+ | id | name | testfield | status | +----+--------+-----------+----------------+ | 1 | raju | ...
1
vote
1answer
34 views

Weed out certain rows where timestamp is within interval

Given a table structure: create table contacts ( contact_id int(8) not null auto increment, #primary key pid int(8) not null, #personal id contakt_time datetime, ...
0
votes
1answer
42 views

Hibernate query results are missing rows with empty value in filter columns

I have two tables with foreign key references: Comm TABLE: +----+------------+ | ID | NAME | +----+------------+ | 1 | comm name1 | | 2 | comm name2 | | 3 | comm name3 | +----+------------+ ...
0
votes
1answer
42 views

select row where a couple of column values is different [closed]

I have a table A with thoses columns : date, ip, created_by. I would like to display date, ip and created by of rows where for one ip it exists different created_by. Thank you I explain more : ...
1
vote
2answers
110 views

sql join with laravel query builder

I have a transactions table with the following field: Transactions ID | amount | branch_id | supplier_id 1 | 1,200 | 2 | 1 Subsidiary ID | Name | Type 1 | supplier1 | 0 2 | ...
2
votes
1answer
22 views

How to do housekeep the database in sql server 2008 by specific date range?

I have database with around 160 GB size. The database contains the data is from 2013 to until today, there are 180 tables, I want to remove the records in specific date range like 2013 to 2014 in all ...
2
votes
0answers
26 views

How do I keep a postgres table up to date using instagrams api?

I want to update a table in postgres with the response I get from the instagram api. I saved the response as a json file and imported it using navicat but when I saved the import job in navicat it ...
1
vote
0answers
28 views

Complicated MySQL table reorder

I should do really complicated tables reorder. ****The main table looks like:**** id - some data 1 - ... 2 - ... 3 - ... 6 - ... 9 - ... 12 - ... As you can see, there are "empty" IDs (no 4, 5 ...
4
votes
1answer
172 views

Is this a sane model for a network provisioning system?

I'm sketching out a model for a network setup, where I have the following conditions: There are multiple nodes which contains a number of switches each. Each switch has multiple services, which may ...
3
votes
1answer
30 views

Single table or multiple table design when records have a clear distinction but are queried together?

Let's say I have the following types of recurring data (all types periodically come in). Post (Title, Summary, Text, Timestamp) Image (URL, Caption, Timestamp) Event (StartDate, EndDate, Title, ...
3
votes
1answer
65 views

Importing via sqlcmd errors out

PS C:\Users\administrator.INTERNAL\Desktop> sqlcmd -S SQLMAIN\MSSQLSERVER -i rdmdb.sql Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : SQL Server Network Interfaces: Connection string is ...
4
votes
1answer
45 views

Select a count with some conditions

Using Postgres 9.4, I have a table page_views which has a page column. I'd like to select all the distinct pages and have a count before them and sort them descending. I'd also like to have a minimum ...
1
vote
1answer
22 views

Trigger is failing with no errors at all, why?

I need to UPDATE territory_id column at pdone.reps table by using and filtering results from veeva_new.userterritory so based on the answer I got here I am trying to build my own and this is how it ...
3
votes
1answer
25 views

Information about a column and the data it holds?

I'm working with a table that has 3 different dates associated with each item in the table. I don't understand what each time is so I want to know if there's a standard place that the person who made ...