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)

1
vote
1answer
497 views

mysql query - how to delete duplicates based on highest int?

I'm running a reverse auction website and I need to delete the duplicate bids and keep only the highest amount . lastPriceBid_rounded is the "amount". The duplicate is defined by the userId. ...
7
votes
2answers
1k views

Different results rebuilding an index online and offline

I have a non-clustered, non-unique index on a foreign key column of type bigint. When I rebuild the index online, the average fragmentation drops to 3%, with 2 fragments, and 30 pages. When I run ...
6
votes
4answers
567 views

Is a join optimized to a where clause at runtime?

When I write a query like this... select * from table1 t1 join table2 t2 on t1.id = t2.id Does the SQL optimizer, not sure if that is the correct term, translate that to... select * from table1 ...
4
votes
1answer
81 views

Index Evaluation

I have been doing some index evalaution on a table and this is the first time I have ever looked at how well indexes are performing so and would like some advice on a certain index. The non ...
2
votes
0answers
219 views

Limit Output Flat File Size In SSIS

I am using Flat File Destination to export my data's to a Text file. I need to limit the output File size to 1 MB. Is it possible?
2
votes
1answer
3k views

Select the top 5 records and the specific column from each table in the same database

I have 50+ tables in a database. I don't want to use the following SQL on each table in a database. select top 10 * from {table_name} So, is it possible to display the first 10 records PLUS only ...
0
votes
3answers
4k views

How to select the first 10 records for each table in the same database using sql

I have 50+ tables in a database. I don't want to use the following SQL on each table in a database. select * from {table_name} So, is it possible to display the first 10 records for each table ...
2
votes
2answers
1k views

What is the difference between using varchar(100) and varchar(255)?

I want to know difference between varchar(100) and varchar(255) in terms of memory usage and programming problems of using more memory.
0
votes
2answers
71 views

some tips on setting up sql server database server

I am currently setting up a new sql server database server with databases. It is supplied by a third party company. I need to request access for them around ports etc. I would like to be able ...
1
vote
2answers
193 views

Suggestion for storing a lot of simple data

I'm looking to crawl a lot of webpages (500,000,000,000) records and be able to store the linking structure for a later date. The way I planned on laying out the database was as follows: 2 Tables ...
3
votes
1answer
68 views

Special ordering

I have a hierarchical query but I don't manage to order it as I want. I have a column named sequence that indicates how to order it but the data is kinda mixed up and I cant do it properly. This a ...
7
votes
2answers
874 views

Is there any difference between putting a column alias at the start or the end of the column definition?

I've always seen and written my column aliases as SELECT 1 as ColumnName but today came across a query that used SELECT ColumnName = 1 Is there any difference in how these two queries get ...
0
votes
1answer
245 views

Connecting to an SQL Azure Database from SSMS - IP Restriction

I am trying to connect to a new SQL Azure Database via SQL Server Management Studio. The client box running SSMS is hosted on a production DB so we restrict access on 1433 to just a handful of IPs ...
5
votes
3answers
126 views

Filtering data that could have more than one category

I have a table like the following: Annotation ( document, term, category ) Where document and term are some ID, while category is an integer. The couple document - term is not unique, ...
2
votes
2answers
988 views

Problem with order by in MySQL subquery

I'm running a query that runs in about 2 seconds when the subquery does not include the order by date_sold clause. However, when I add the order by clause, the query runs forever. I'm confused, since ...
0
votes
2answers
89 views

How to organize a single query to several sql servers?

I need to make an inner join sql query to several SQL Servers (one is 2000 and another is 2008 R2). The query is like the following: SELECT k.ID, k.NAME, k.BIRTH, l.PROFILEID FROM ...
0
votes
1answer
72 views

Faster joining on 'most recent' related rows

I have a bug tracking application. The bug table stores very little, because every state change to a bug happens by adding a comment. For example, the current state of a bug is determined by the state ...
2
votes
3answers
4k views

How to import table's data in MySql from Sql Server?

I am trying to export table from SQL Server 2008 R2 TO MySql 5.5. For this I am using SQL Server Import and Export Wizard of Sql Server 2008, but it is giving this error. Here this error may be ...
7
votes
2answers
1k views

Select longest continuous sequence

I am trying to construct a query in PostgreSQL 9.0 that gets the longest sequence of continuous rows for a specifc field. Consider the following table: lap_id (Serial), lap_no (int), car_type ...
1
vote
1answer
715 views

How and what is the most efficient way to join two tables, retaining a particular field from both?

I have two tables, with the following columns: Table 1 ID Component Data1 Data2 Table 2 ID Component Data3 Data4 If I have rows in these tables, with items Component1, Component2, Component3, ...
3
votes
1answer
74 views

Locating row in index page

In clustered index, we have root, intermediate and leaf level pages. Every page has few records where indicating range of pages from level below. How SQL check whether some index key belong to ...
2
votes
2answers
127 views

Query to find Maximum friends not giving correct resuts [closed]

Table Schema for the Likes table: id id1 1 2 1 3 2 1 I count the total number of Likes for each student with this: select id,count(*) from friends group by id I have to find the students with ...
1
vote
1answer
156 views

Mysql setting a record as deleted or archive

Is there any way to omit some records in mysql select statement and not deleting them? We can easily add a column for example deleted and set it to 1 for deleted ones and keep them but the problem is ...
0
votes
0answers
353 views

Understanding the time difference between data grid initial display and export/full display using Toad for Oracle

I am trying to run a query on a local Oracle DB and output the results to a .CSV file. The query runs in a decent amount of time (usually less than 5 minutes), but returns tens of thousands (possibly ...
1
vote
1answer
1k views

Strange behaviour of a query with order by and rownum on Oracle's Exadata server

I am executing the following query on two different database servers: SELECT start_date, end_date, resort_id FROM employee_activity WHERE employee_id = 27 AND start_date < ...
4
votes
1answer
564 views

Query records that chain together based on date gaps

I have a table in SQL Server 2012 with the below simplified schema and I need to define a query that grabs the most recent record and then returns the chain of records that have less than 30 days of a ...
1
vote
2answers
3k views

SQL Server - backup / restore schema only (not a duplicate if that's what you're thinking!)

We have a DB on over 100 servers of which we want to backup / restore the structure of just 1 at a time to a specific UAT database. They're all called the same thing but vary in terms of schema - ...
3
votes
2answers
10k views

Selecting data from multiple rows into a single row

I have a table that has columns like following. Batch number is a database design thing like row number demand_id batch_number debit status customer 34 1 ...
0
votes
2answers
2k views

Does MYSQL join before LIMIT?

Imagine that I want to populate the last 10 questions of stackoverflow. I have a table that keep the questions list, a table to keep the question info, a table to list question's asker. Now imagine ...
4
votes
2answers
612 views

How to sort category by path and sort order?

first of all I am sory for my english. My category structure is shown below. My purpose is to get category structure with single query. I sort my table by path and I get category tree. sort_order : ...
0
votes
1answer
45 views

Need Some SQL help [closed]

I need to pass the following SQL statement: UPDATE table_products SET shipping = "a:5:{s:16:"min_items_in_box"; i:0;s:16:"max_items_in_box"; ...
2
votes
2answers
1k views

how does SQL Server 2008 handle joins internally?

for example, I have tables: User and Order User Table: UserId, Name, Address, Phone, Age Order Table: OrderId, UserId, Date, Item, Quantity SQL: select User.Name, Order.Date From Order JOIN User ...
1
vote
1answer
61 views

Correct data model for users with clients

I have an application where users are granted access. Part of the system allows users to have their own 'clients'. I have a users table ******************************** users ...
1
vote
1answer
173 views

Multiple primary keys

I am new to database design and have been looking at some example data models here. One thing I don't understand is if you have a table like client_addresses from the link above: ...
1
vote
3answers
100 views

Live monitoring SQL statements on SQL Server

How can i monitor running SQL Statements for my SQL-Server, is it possible using only SQL Server without 3rd part tools? As an alternative can anybody recommend any free tool which can monitor ...
1
vote
1answer
742 views

Query is not using indexes on third table in left join

My query is not using indexes on third table(pci promotion_coupon_images) . i was tried with using index and force index in query but there is no change in result. any body please suggest me how ...
8
votes
3answers
1k views

SQL Database Structure for RESTful API

I am creating a RESTful API. I am struggling to decide on the best way to design my database tables around my resources. Initially, I though a table per resource would be a good way to go, but I'm ...
3
votes
2answers
7k views

ORDER BY clause is allowed over column that is not in SELECT list?

In theory, every statement in SQL Server create virtual table passed to next statement. In other words, when FROM and Where clause are finished, next step is SELECt columns from virtual group created ...
0
votes
1answer
293 views

Create a VIEW that spans 3 tables

Sorry if the title is not clear - feel free to improve. Here are 3 tables (not all data is relevant to the question): CREATE TABLE `content` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, ...
1
vote
1answer
43 views

simple query is not using indexes

My query is not using indexes. it was taking around 5 seconds. output is 500 rows only. it is a simple query Please find the explain plan and table structure here. Explain Plan mysql> explain ...
4
votes
2answers
737 views

Restore SQL Server database from .sql files

So we had an encrypted database that puked and killed our whole SQL Server setup. Sucks about our data, but we were smart enough to have our data structures / stored procedures / functions in Git The ...
2
votes
1answer
128 views

index doesn't work properly

I have this query SELECT user_id, MAX( highscore ) AS highscore, stage, COUNT( * ) AS count FROM single GROUP BY user_id, stage table engine is innodb, plus I haven't use any indexes except one key ...
0
votes
1answer
269 views

Postgresql: Return Unique Rows

I'm using postgresql and I have a large database. A simplified version of the datastructure for my table looks like this: id (primary unique key), data, userID 1, foo, 4 2, foobar, 4 3, lala, 5 4, ...
2
votes
2answers
363 views

Query design for tracking order status

I have the following tables in MySQL `orders` ( `orderID` int(10) unsigned NOT NULL auto_increment, `agentID` int(10) unsigned NOT NULL, `order_date` datetime NOT NULL, `senderID` int(10) ...
4
votes
0answers
1k views

Receiving error Error: 18059, Severity: 20, State: 1 in the SQL Logs

I'm using SQL Server 2008 Sp3 Lately I'm having errors in the SQL Logs: Error: 18059, Severity: 20, State: 1. The connection has been dropped because the principal that opened it ...
1
vote
1answer
182 views

MySQL query to search string in Master-Child tables and return all rows with Master-Child relation

Need MySQL query Help. Please find schema below: Table1 PK_id Table1_Title Table1_Description 1 Test1 This is Test1 2 Test2 This is Test2 Table2 FK_id ...
8
votes
2answers
347 views

Where can I find the SQL standard document?

Where can I find a legal copy of the ISO SQL 2008 standard?
1
vote
2answers
2k views

Oracle insert max from two date

I want to create an insert statement in a PL/SQL Script that inserts the larger of two different values. Conceptually, what I want to do is something like Insert into MYTABLE (DATE_INSERT) VALUE ...
0
votes
0answers
128 views

Performance Optimising MySQL query

I have this query in my mysql database, when i execute this, it takes about 4 sec. To give me the result (on xampp 1.8.0 with mysql 5.5) I was wondering if there is any way to enhance this query so ...
1
vote
1answer
170 views

Mysql query - find out 1000th row from a table for each user

Lets say I have a table where we log activities of user, I need to find out created_at of the 1000th activity of each user.. Following query works fine for one user.. select `created_at` from ...