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)

-2
votes
1answer
39 views

Usage of COALESCE? [closed]

Today: table abc a b c d ---- ---- ---- ---- 1 null 2 3 null null null 7 null 5 null 4 1 = e 7 = b 5 = f 3 = i 2 = w 4 = o The Goal is to retrieve this ...
0
votes
1answer
37 views

Options for structuring multiple associations to a record

This is 101 level stuff and I promise to read a book later, but in the meantime, given the following three tables: Product --------- ProductId (uniqueidentifier) User --------- UserId ...
7
votes
1answer
897 views

Why 0 is equal to empty string?

I need some help in finding why the following T-SQL statement returns 1 (true): SELECT IIF( 0 = '', 1, 0) I guess someone has change an ANSI option like SET ANSI_NULLS or something else that is ...
0
votes
2answers
59 views

Single query for searching for records without knowing what the search column is for

I have a single line search where i should be able to search for address or city or zip or state. I should be able to show data of what ever that matches for the typed in word. Suppose user had typed ...
3
votes
1answer
100 views

How to index for timestamp queries

I have a products table where I insert around 150,000 records a day. Most of them are redundant, but I need to keep them because of the new expiration date. I get product feeds from about 5 vendors a ...
0
votes
0answers
37 views

Insert Unique Records into Linked Server Table (from SQL to Oracle)

My issue is that I am trying to load only unique primary key records into oracle from sql. In the insert into stored proc statement I tried doing it by where primary key does not equal primary key ...
0
votes
2answers
61 views

Database Design - Cardinality

I am currently studying for my MTA Database Fundamentals cert, and I came across this question during my studies. However, the answer doesn't make any sense to me. Here is the question/answer: It ...
0
votes
1answer
31 views

Postgres: Disable “similarity” column output on “SELECT SIMILARITY”?

I've tried disabling similarity column output on SELECT SIMILARITY but still cannot. Below query will generate a column similarity: SELECT SIMILARITY(title, 'Nation'), title FROM gallery WHERE title ...
1
vote
3answers
55 views

Load specific element from XML

I have the following xml: <root> <123 type="line"> <aa type="item"> <value>1</value> </aa> </123> <234 type="line"> <bb type="item"> ...
0
votes
1answer
30 views

How to serialize on SQL server metadata?

I tried to find an answer in Kalen Delaney's SQL Server Concurrency but there is no mention of metadata. The problem is how to ensure that only one of these reads and index creates executes from one ...
5
votes
2answers
89 views

Why do so many queries have aliases? [closed]

I've spent a lot of time searching for, researching and implementing various complex MySQL queries over the last several years. Many of them use lots of aliases for tables, even when none are ...
0
votes
0answers
36 views

What is wrong with my ERD?

I am trying to create a reservation/booking ERD. Is their anything wrong with my current ERD? It must show a supertype and subtype, and it must identify attributes for regular, weak, and associative ...
1
vote
1answer
58 views

How to Get one Single statement of two table value in SQL

I wanted to retrieve two table values in one single statement such as, (Example Bank statements..) Table 1: Invoice SELECT ClientNo, InvoiceDate, InvoiceNo, TotalDue FROM Invoice_TBL WHERE ...
6
votes
2answers
69 views

Select lowest ID and calculate deviation from the lowest

I'm trying to create a view. I have some data in my SQL Server database, and I want to order them by their mark1 and mark2. Now when I sort them I want to select the mark1 who has the lowest mark2 and ...
1
vote
4answers
66 views

Getting an aggregate (here: min) for a group of values [closed]

Example table: ID | value A | value B ---------------------- 1 | abc | 3 1 | def | 5 1 | ghi | 1 2 | cba | 9 2 | fed | 4 I want the ...
0
votes
1answer
19 views

How do I merge two rows only if there is the TagWidgetIds are same but the tagValues are different?

I have this stored procedure which generates the following output. The query which generates the output from the stored procedure is as follows: SELECT tat.[agent-id], ...
0
votes
2answers
54 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
46 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
81 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
13 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
39 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
96 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
38 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
53 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
38 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
101 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
13 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
142 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
78 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
49 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
57 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
43 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
18 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
20 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
31 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
95 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
72 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
53 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
30 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. ...
3
votes
0answers
24 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
41 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
102 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
27 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: ...
10
votes
3answers
150 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
27 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 ...
3
votes
0answers
40 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 ...
1
vote
1answer
34 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
33 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
113 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 ...