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
59 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
62 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
29 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
37 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
43 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
18 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
100 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
56 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
82 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
66 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 ...
0
votes
1answer
37 views

Displaying only the most recent activity of an item

I have made a database that tracks the shipping and receiving of the tools that my company has. I am now wanting to make a query that shows only the most recent activity of all the tools. I have a ...
0
votes
0answers
42 views

What is the difference between normal Select query and a Select query inside Common Table Expression(CTE)? [duplicate]

I'm having a table 'Products' and if Execute this query SELECT TOP 1000 [ProductID] ,[ProductDesc] ,[ManufacturingDate] ,[ExpiryDate] ,[Price] FROM ...
1
vote
1answer
60 views

Grouping() equivalent in PostgreSQL?

I have a SQL query that runs in MS SQL Server and it has grouping(), rank() and rollup() functions / keywords in it. The query is given below. How can this be translated to PostgreSQL? select top ...
0
votes
2answers
43 views

Grouping rows by looking at two columns without considering the order and summing each separately

I have a table looks like this one below: +---------+---------+-------+ | SOURCE | DEST | VALUE | +---------+---------+-------+ | A | B | 1 | | B | A | 2 | | A ...
0
votes
2answers
35 views

wildcard expansion using sql

I've a table named permissions. CREATE TABLE `permissions` ( `id` int(11) NOT NULL AUTO_INCREMENT, `role_code` varchar(45) NOT NULL, `permission` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ...
1
vote
1answer
48 views

Convert Varchar Duration time to time

I need my code to add the varchar CPUTM field + varchar CPUZIPTIM field which both has time values to see if greater than 2 hours. How do I do this when both fields are varchar. The value in CPUTM ...
2
votes
1answer
48 views

Better way to select from nested tables in PostgreSQL

I have the following schema with millions of rows in the match table and each match have two sides (away and home). I want to create a view which shows the most significant data regarding the matches ...
1
vote
2answers
32 views

Calculating the number of times a motive was cited over a given period

I'm using PostgreSQL 9.4. I have the following surveys table. Each row includes a motive that was cited by the respondent, represented by the motive_value column (think of it as motive_id). ...
0
votes
1answer
72 views

How to achieve using TRIM command on SELECT * From TABLE

I am building DWH where in source data dump is made through SELECT * query into DB. I am taking dump from the source DB, to save time (else had to write 115 select stmt using TRIM where average number ...
0
votes
1answer
55 views

Index rebuild canceled because of .mdf growth

I have the Standard Edition of SQL Server 2012 and used a script to rebuild index. I ran the query and then I saw that the .mdf file for the database started the grow a lot. I chose to cancel/stop my ...
1
vote
2answers
65 views

Combine results of two queries, where the second relies on the first

I have one query which is returning name(text), total, created_at And another query which is returning the same thing name(text), total, created_at The second query usually is returning more ...
5
votes
2answers
130 views

Sporadic execution time causing timeouts [closed]

We have a table with 100 million records holding 24 hour worth of data of our clients' customers actions (actions which are performed on 3rd party sites and replicated from there to our server) The ...
1
vote
2answers
47 views

Combine multiple similar queries into one

I need to calculate a weighted average using the following table. I have to calculate this number for metric_1 up to metric_10. All the metric columns have a value from 1 to 5. ...
0
votes
3answers
41 views

Group by transformed column

I have a database with creations and orders, and a bunch of tables linking them. I want to extract, for each month, the number of ordered creations, and the sum of amount for these orders, but for a ...
0
votes
1answer
27 views

Dropped column still has value when recreated with Postgres table of 150M rows

I need to set the column to NULL. Until now, this has worked, but for some reason, on this table which is much larger than the rest, it doesn't seem to be working: ALTER TABLE ...
0
votes
0answers
45 views

sql taking < 1 sec to run in sql developer, 37 on the application side

As the title says, we have a big discrepency between a sql query we're running from our java application (jdbc thin client) and the same query run in sql developer. I clear the cache of the query ...
1
vote
2answers
57 views

What is the best way to compare values of whole tables between many databases?

We are trying to compare the values of whole tables between many databases. The user can enter in input the table names and the columns names, and the database names he wants to compare. They can ...
0
votes
1answer
80 views

More Best Practices To Updating Large Tables?

I know there are a number of topics on this question, but I'm always seeking more insights. I have a large table with a billion+ records. The amount of records could be reduced and archived, but the ...
0
votes
1answer
74 views

How to set foreign key in table in one database that references a table in another database [closed]

Msg 1768, Level 16, State 0, Line 1 Foreign key 'FK_id' references object 'dbo.student' which is not a user table. Msg 1750, Level 16, State 0, Line 1 Could not create constraint. See ...
0
votes
0answers
19 views

Timeout expired error when database is being backed up in SQL Server 2012

We have daily full backup scheduled at 8.30 AM. We are getting Timeout expired when we try to access a web page using the database being backed up. The web page has several select and few ...
1
vote
1answer
61 views

A query for merging date intervals

I have a simple table with 3 columns: (cid, from, to) -> (int, datetime, datetime) The difference between dateFrom and dateTo should be >= 1 month. And unfortunately i have some corrupt data ...
1
vote
1answer
39 views

Performance of Combination lookup

I've been looking into this most of the day and I'm still not getting far so I thought I'd ask on here. Basically its a lottery system and what I need to do is check whether 4 of the 6 balls I have ...
1
vote
1answer
29 views

Need help rectifying IN/NOT IN clause

Hi there everyone! I have built a link/content sharing site. The way it works is that each link can have multiple categories assigned to it. A video of a motorcycle race might have motorcycle, ...
1
vote
1answer
37 views

Add multiples of rows till they satisfy an arbitrary sum then return the rows that do

Am not sure if this is possible. Let's say I have an arbitrary figure like 200, I have a table with two columns (both ints). Lets call the columns col_a and col_b. I need to perform one query such ...
0
votes
0answers
20 views

Manage duplicate records and other entries based on duplicate records in MySQL

I have following list of tables for my PHP Application. wi_individual_g(ind_id,ind_name,ind_father_name,ind_spouse_name,is_employee,org_id,ind_dob,...) wi_individual_p(ind_id,prg_id,...) ...
0
votes
0answers
21 views

Oracle SQL Updating Trigger Statement

Hey all so let me see if I can clearly explain what I would like this trigger to exactly do. First of all the trigger will deal with 2 tables: Delivery Table: DeliveryNum |ItemName | Quantity | ...
0
votes
0answers
41 views

SQL Server Job Database name

First time post, long time lurker. I am trying to find and write a query for what database is affected by a SQL Server job. I have checked the following: Get a list of SQL Server Agent Jobs and ...
1
vote
2answers
65 views

Query for orders that contain a product without using sub-query

Order ----- OrderId OrderDetail ----------- OrderDetailId OrderId ProductId How do I write a query that returns all orders that contain a specific product without using a sub-query? I don't want ...
0
votes
2answers
39 views

How to list LOGIN + ROLE in SQL Server 2008?

I'm looking for an answer but i can't found. Just a lot of long scripts. I need to list Login | Role ( sysadmin, dbcreator, etc ) but i can't find a table to join. I have this for now: SELECT name ...
0
votes
0answers
13 views

Data base design for handling website subscriptions

I have a website where at least 20 posts are posted in a day and each post contains more than 5 categories and each category has further tags. I wanted to build a subscription module that users can ...
0
votes
1answer
60 views

Order of Columns in Index

I have following query which has ON clause on different column, Where clause on different column and Selection on different columns so my question is what should be Order of Columns in Index as ...
0
votes
2answers
45 views

SELECT that is null if there is one more register in this date that is not null

I'm trying to make a query that I can't produce... This is my table capturainfo captureid int(11) userid int(11) date date dateinit datetime datefin datetime I need to select ...
1
vote
3answers
145 views

run a script for all databases

I need help what statement or function i can use to run a query in all database using one script , i want to run the below script at the same time to retrieve output in all databases select ...
0
votes
1answer
81 views

ON DELETE CASCADE not deleting entry for foreign key

I am running the below query in ideone CREATE TABLE AUTHOR ( AUTHOR_ID NUMBER(5) PRIMARY KEY, AUTHOR_NAME VARCHAR2(18) ); INSERT INTO AUTHOR (AUTHOR_ID, AUTHOR_NAME) VALUES (1234, 'MC GRAW HILL'); ...
0
votes
1answer
38 views

Oracle SQL Summing Values From Two Different Tables

Hey all so I am trying to add to (or subtract from) a column of different values based on a separate column in another table. Here is a example of what I am tying to do: Table 1: (Current Inventory) ...
0
votes
0answers
22 views

Windows Administrator doesn't have permission on SQL Server [duplicate]

My previous system administrator created a SQL Server 2008 instance on my local machine with his domain User. Now, I cannot create, delete, or view any databases or tables on that instance. Even with ...
0
votes
2answers
104 views

Combining multiple rows into single column

The return from my MySQL statement displays an example below: id 1 | status | id 2 | name | category 001 | open | 011 | john | person 001 | open | 011 | john | male How would I combine the ...
0
votes
1answer
39 views

Join to a Culture Table vs Select Culture ID

I have a query that is executed several hundred thousand times a day. Due to legacy support, the incoming variables on this SP cannot change. Currently it looks like this: Select id, name, ...
0
votes
1answer
39 views

Display a one-to-many relationship in one row

I have a "one to many" relationship in two tables: Table "products" contains: product_id, product_descr Table "packing" contains: product_id, package_id, package_desc One product has often more ...
3
votes
2answers
148 views

Is EAV an appropriate design for a collection of coexisting metadata-rich “fact estimates” on objects? [closed]

I'm attempting to architect a system that will collect estimates on various quantities (10+) on each of many (300K+) objects, and make decisions from the historical record of these estimates. For ...