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
2answers
40 views

How to get several specific records from a query result?

I know by using Like with "LIMIT 1, OFFSET x" I can get the Xth record from a returned query result. But what if I want to get X, Y, and Z all at once? Currently I do a for loop and it's like I'm ...
0
votes
2answers
38 views

How can I find table name for each row result?

How can I find the table name for each row result in my query? I have tried ideas suggested on the stack network (overflow, dba) 1 How to make a table name an attribute in PostgreSQL? 2 ...
2
votes
1answer
71 views

How to display the query result separately for each item in an IN clause? [closed]

Maybe it's a novice question, but I am trying to get the sum of balances for each account present in the table. I am trying the below Select SUM(BALANCE) from dbo.account_balances ...
0
votes
0answers
8 views

SQLAnywhere: How to apply function to list members?

I'm a newbie to SQL Anywhere... what a difference from the big O! I'm working in SQL Anywhere 12. I have a query that returns a column values that are a list of big int numbers, EXAMPLE: ...
0
votes
0answers
32 views

Find the Minimal Basis

Suppose we have relation R ( A ,B ,C ,D ,E ) , with some set of functional dependencies, and we wish to project those functional dependencies onto relation S(A, B, C). Given the functional ...
2
votes
1answer
95 views

search xml column inside large table (7 million rows)

Database design: Table Name : Plays ( 6 million records) Columns: Play id, col1, col2......col7, PlayFieldValues PlayFieldValues xml column. sample xml stored in this column <PlayAttributes> ...
0
votes
1answer
31 views

Select records as groups based on sequence and date

I have data stored as: CompID | Seq | Udate | Utime --------+-----+-----------+------- mx433 | 1 | 1/1/2012 | 13:54 mx433 | 1 | 1/2/2012 | 13:43 mx433 | 2 | 1/4/2012 | 14:23 mx433 ...
0
votes
0answers
12 views

I want to sync local mysql database and live server mysql database

My plan is 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'm have a inventory ...
1
vote
1answer
32 views

Selecting the correct row given multiple input value combinations

I have a table that stores part numbers for various items like so: +------+-------------+-------------+-------------+ | Item | Color | Type | Part Number | ...
4
votes
1answer
87 views

Finding all joins required to programmatically join a table

Given a SourceTable and a TargetTable, I would like to programmatically create a string with all joins required. In short, I am trying to find a way to create a string like this: FROM SourceTable t ...
0
votes
0answers
11 views

How to capture a manager highest level from bottom in mysql?

So I have a giant table of 100K employees. Every employee has a supervisor except our top boss. I want to capture a manager's level from the bottom. Sounds simple but now I have a series of views ...
1
vote
1answer
126 views

UPDATE with CASE with 2 tables

I have 2 tables and I want to update table2 with criteria of table1 and table2. The criteria are: 1.table1.amount > 10000 2.table2.flag is null or table2.flag = '0' So if the 2 conditions are ...
1
vote
1answer
74 views

Help on deciding how to pick Correct Index

I would like to ask for some help to create correct indexes for this query: SELECT DISTINCT D.TypeID FROM dbo.Sizes AS S WHERE EXISTS ( SELECT 1 FROM #PermissionsTable AS PT ...
0
votes
2answers
39 views

SQL query to list software by major versions

I have the following code i am tiring to get it to only show one line in the results for each major version, i need to combine all of the rows that are the same Like so. SELECT COUNT(arp.displayname) ...
0
votes
1answer
31 views

Optimizing key lookup in subquery with UNION ALL

I am trying to optimize following query (little bit more complex actually, but this is important part): SELECT Id, StatusDate, [...Lot Of Columns...] FROM ( ( SELECT Id, StatusDate, [...Lot ...
0
votes
1answer
36 views

How to convert rows into columns and query on them in Mysql?

I have three tables Patients, which contains the name of my patients, Controls which represents the UI controls which could be drawn for each illness , and ControlsValues table which contains the ...
0
votes
2answers
16 views

In MySQL, get number of pregnant women who received 3 ANC checkups

I am working on a project where it is required to find out the total number of pregnant women who have received 3 ANC(Ante-Natal Care) checkups done. A pregnant women is said to receive 3 ANC ...
-1
votes
1answer
17 views

SQL statement for comparing actual products and plan products

I need some helps for writing SQL statements to compare count of actual products and plan by like below 2 Input tables: CREATE TABLE PRODUCT_PLAN ( PRODUCT NVARCHAR(50), START_TIME ...
-1
votes
1answer
29 views

Retrieve Column name as Data [closed]

Based on this code below from adventurework, I would like to display the name of the column as a data in the first row and the remaining rows are data of the column. I do not know how to do it. ...
0
votes
1answer
51 views

Invalid object name 'sys.dm_os_volume_stats'

I am trying to select 15% of disk space available in a server. SELECT DISTINCT s.volume_mount_point [Drive], CAST(s.available_bytes / 1048576.0 as decimal(20,2)) ...
0
votes
2answers
63 views

Index on Column with only 3 status?

I have a table with millions of rows. This table has a column which we frequently filter(means we use it in WHERE clause frequently), the values are Insert/Update/Ignored. Is it make sense to add ...
0
votes
2answers
45 views

Speed up SELECT with WINDOW, (PARTITION … ORDER) with compound index

I have the following table: CREATE TABLE ranking_points ( id serial NOT NULL, store_id integer, book_id integer, list_name character varying(255), rank integer, created_at timestamp ...
1
vote
1answer
29 views

Create Table not working

Forgive me if the question is very simplistic; I am a bit of a novice when it comes to SQL. The following CREATE TABLE syntax was generated by MySQL workbench from my model; It gives me errno: 150. ...
2
votes
0answers
18 views

Superkeys of this relation

I am trying to find the superkeys of this relation, but I am having troubles finding out how many superkeys there are and exactly what they are. I figured out that the candidate keys were ...
1
vote
1answer
31 views

Getting Data Type ID in MySQL

So, In SQL, We have the following query to find the system data type ID of columns in SQL Server; select name, system_type_id from sys.columns where object_id = OBJECT_ID(N'sometable') It gives the ...
0
votes
1answer
33 views

Query Netezza to find all tables in views

I am trying to recreate the following query in netezza and am struggling: SELECT view_name, Table_Name FROM INFORMATION_SCHEMA.VIEW_TABLE_USAGE WHERE View_Name = '' ORDER BY view_name, table_name ...
1
vote
2answers
26 views

mysql copying to tmp table duration

I have a web site which started to have performance issues because of a mysql query which is executed for each request. I have the following table structure. Post table (125000+ records) id: ...
9
votes
3answers
119 views

Combining separate ranges into largest possible contiguous ranges

I'm trying to combine multiple date ranges that may or may not overlap into the largest possible contiguous date ranges. For example: Data: CREATE TABLE test ( id SERIAL PRIMARY KEY NOT NULL, ...
0
votes
2answers
23 views

How to get a column of the select to be “cumulative” (like in excel)?

This simple query (written in MySQL) is counting the number of WP posts published every day. But I need another information. I want to know the cumulative number of post for each date returned by the ...
2
votes
0answers
26 views

SQL Agent Jobs Automatically Disabled After Modifying Maintenance Plan

Hoping someone can shed some light. I modified a maintenance plan yesterday, to find out this morning (by using the last modified date from sysjobs) that all jobs related to the maintenance plan are ...
0
votes
0answers
11 views

DB design for video-annotations, where annotations have no unique id [migrated]

Right now i have a program in java with 2 classes: public class Video { private String id; private ...
1
vote
1answer
26 views

wm_concat in a specific order

I have a query that makes something like this: +---------+---------+------+ | Patient | Pattern | Rank | +---------+---------+------+ | a | 0 | 1 | | a | 1 | 2 | | a ...
0
votes
0answers
31 views

I want to pivot a table and aggregate a column into strings [duplicate]

I have a select statement producing the following: +---------+---------+------+ | Patient | Pattern | Rank | +---------+---------+------+ | a | 0 | 1 | | a | 1 | 2 | | a ...
2
votes
1answer
27 views

I want to make a new column based on another column

I don't want to make a new table; rather, I want my query to produce the desired output. I have a query that produces a bunch of columns, and then a PROGRAM_ID column which only has 666 or 667. I ...
0
votes
0answers
61 views

Sudden High CPU Usage On SQL Server 2008R2

Our SQL Server is experiencing sudden high CPU usage since 12:30am today. This server is used internally so nobody should be accessing the server at that time. I'm not sure why 12 hours later the CPU ...
0
votes
0answers
28 views

Challenged with modeling a big DB

I'm tasked to develop a gaming web application system with relatively large database - it should hold the data about 300 million players, the orders/payment of each player - ~3B records - , and other ...
0
votes
1answer
38 views

Put Postgres query result in array

How can I put an sql query result in a string array with Postgres? I have some attributes in the column 'zone' of the table 'mytable' and I must put them all in a String[] areas; This is my first ...
0
votes
0answers
10 views

inserting multiple rows with two input fields with same names [migrated]

HTML <tr> <td><input type="text" name="description"/></td> <td><input type="text" name="quantity" /></td> <td><input type="text" ...
1
vote
1answer
57 views

Moving a date between tables is causing error ORA-01841 [closed]

Here's my script: INSERT INTO BRAND_RECORD SELECT STRENGTH, GENERIC_NAME, TO_DATE(a1.FIRST_CLAIM_DATE) as INTERCHANGEABILITY_DATE FROM DRUG_INFO INNER JOIN ( SELECT ...
0
votes
1answer
31 views

Updating across row and column in SQL

Bit of a strange question. Entries in this table have three relevant columns; drug, date_1, date_2, seq_id I am trying to make it such that every drug with the lowest seq_id has a date_2 equal to the ...
0
votes
1answer
33 views

OR Operation in JOINS SQL(MYSQL)

I am using MYSQL SELECT m.proposalId, m.title, n.stageNumber, n.committeeId, n.modifiedDate, o.msNumber , o.description,o.ics,o.edition FROM mystands_Proposal m INNER join ...
0
votes
1answer
61 views

How to exclude weekends and holidays in a query

I have been tasked with creating a flat file. One of the fields that I need is a date field. I need the disco date to be LAST_EVENT_PROC_DT + 12 unless that date falls on a weekend or holiday,if so ...
0
votes
0answers
15 views

Convert SQL OPENXML to XML Nodes Value [migrated]

Can anyone help with converting the following from OPENXML to Node protected virtual void ApplySqlXmlSetupSql() { if (!this.query.HasFilterBySectionList && this.query.IgnorePermissions ...
1
vote
1answer
25 views

Repeating rows of date intervals based on another table in Oracle

I have a table of maintenance plans with date intervals between each required maintenance period. Fiddle: http://sqlfiddle.com/#!4/af742 create table maint_sched (maint_id number, start_date date, ...
0
votes
1answer
34 views

How to Store text of 15 to 20 KB file data in blob or as text? [duplicate]

How to Store text of 15 to 20 KB file data in blob or as varchar in sql Server?
2
votes
1answer
47 views

Create a grouping based on chains of pairs

Say I have two tables: CREATE TABLE datum ( datum_id SERIAL PRIMARY KEY, datum_text TEXT NOT NULL ); CREATE TABLE datum_pair ( datum_id1 INTEGER NOT NULL REFERENCES datum (datum_id), ...
0
votes
1answer
28 views

Filling not applicable fields with N/A rather than leaving them empty or Null [duplicate]

I have a database of few million records, many of the fields (call them Ec1 to EcN) have either Null or empty string in them. When I looked at them more closely, I found that for many records, several ...
0
votes
2answers
123 views

Calculating values from three related tables, without using join or union

I have a simple basic three tables on SQL Server database: What is needed is to get the quantity available, without using joins or unions which is calculated: Quantity Available = Items Opening ...
0
votes
0answers
24 views

Log Shipping Fails to create backup after Server reboot

We made a change last week to point our log shipping backup jobs to a new Windows File Share. For three days everything was running successfully. On Saturday night we performed our monthly ...
0
votes
0answers
20 views

Alternative when IN clause is inputed A LOT of values (postgreSQL) [migrated]

I'm using the IN clause to retrieve places that contains certain tags. For that I simply use select .. FROM table WHERE tags IN (...) For now the number of tags I provide in the IN clause is around ...