An acronym for "Structured Query Language" (it's not the name of a specific DBMS product), SQL can be used in relational database management systems (RDBMS) to query, update, delete, and insert data as well as modify the structure of the database. It can also be used to manage schemas and data ...

learn more… | top users | synonyms (1)

2
votes
1answer
18 views

MySQL WHERE if NULL select another column

This is my mysql table id date_created date_active 1 2014-06-07 18:24:38 NULL 2 2014-06-07 18:24:38 2014-06-07 18:24:38 3 2014-06-07 18:24:38 ...
-1
votes
0answers
27 views

SQL Server Complex Query help needed

Before I begin, I would like to say that I know I am asking a lot but I really really can't figure out any way for the last 3 days and I've been digging like crazy. I would like to start by explaining ...
1
vote
1answer
16 views

Finding out the exact size of the database after inserting records?

I have this query: SELECT table_schema "db.name" , Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" FROM information_schema.tables GROUP BY table_schema; Does this ...
1
vote
1answer
24 views

How to tune the below query

I am currently working on below table structure to pull the data/ generate any one time report. Let us consider the table name to be ABC. ID Field Value 1 Name Nagarjuna 1 Gender Male 1 ...
1
vote
2answers
98 views

Will a non-clustered index on a column with covering index on all the columns of table affect the Delete statement Records)?

I am trying to delete thousands of records say 35K from a table which consists like 10 million records. Delete * from Table where ID=859 I have also tried bulk deletion DECLARE @RowsDeleted ...
2
votes
0answers
48 views

Storing URLs in a database

I am thinking about storing URL's in my database, but I am not sure whether the way I use is an efficient way to do things or not. Table name : url url_id (Primary Key & Auto Increment) url_value ...
1
vote
1answer
36 views

SP how can I sum the amount of all leftchild in parentid

I have this data and table structure,I am creating MySQL stored procedure to sum all the amount in the leftchild of the parentid, I don't have enough knowledge in stored procedure.and I need some help ...
1
vote
1answer
17 views

SQL Server 2008 R2 - Change distributor schedule

We have configured SQL 2008 R2 replication. Distributor is configured in continuous mode, publisher is scheduler is set to execute after every six hours. Now we want to change distributor schedule ...
1
vote
2answers
23 views

How to get the sum of a particular item id in a column

Item ItemName PackageID Specifics brandname GRNQty UnitPric GRNValue 102814742801 ALL BRAN FLAKES 1PKT Bran. KELLOGS 7 15.9 111.3 102814742801 ALL BRAN ...
1
vote
0answers
13 views

pgAdmin-III - Option to load a favorite automatically when opening query window

pgAdmin-III - Query window option Does pgAdmin-III has any option to load a default favorite file automatically when opening new query window? This would be much useful to have commit/rollback ...
-5
votes
1answer
56 views

how to Write a SQL Statement to display EmployeeID from Table1 and EmployeeName from Table2 a [on hold]

how to Write a SQL Statement to display Claim Number, EmployeeID from Table1 and EmployeeName from Table2 above. Write a SQL Statement to display all the Information from Table1 and Table2 for ...
1
vote
1answer
55 views

SQL Server : scheduled JOB issue

I have one issue in my live server ... Issue is: I created a job for log file shrink & I have scheduled it for every day run with sa user When I run this job manually from Management Studio, it ...
3
votes
2answers
38 views

Selecting minimum value in top grouping only

I have a query built in Oracle 10 which produces a set of data like this: EMP_ID WORK_DT TIME_TYPE ---------- --------- --------- 12345 19-DEC-14 10 12345 18-DEC-14 10 ...
0
votes
2answers
27 views

Get all the users that are managed by a targeted manager

I have the following model: Table user: (id, name, direct_manager_id) Table customer: (id, name, managed_by_id) i.e. users can have another user as their direct manager, Customers can be managed ...
-3
votes
1answer
39 views

Finding users with database owner role in sql server 2005 or so [duplicate]

I need a script which will list out all the users with DataBase Owner persmission for a specific database. Thanks
0
votes
1answer
40 views

Run CDC Cleanup job at specified time

I have enabled cdc and using it , it works fine now the problem is that we have many tables in a database and also we have many databases so how to configure cdc cleanup job to run again and again ...
0
votes
0answers
20 views

Is there a DDL/DML statement auto checking tool?

As a DBA, before applying DDL/DML statement written by developers to an online database I have to analyse and check potential limits or danger in these statements, such as: 1.whether a "create ...
1
vote
1answer
37 views

How to insert values into a junction table?

I add values into my two tables using the code below, but I also have a junction table called book_main_cover and I want to add data into this table to make a connection between book_id and ...
0
votes
1answer
26 views

Why Does the Update Statement also updates indexes?

I am currently learning about SQL queries and how indexes work with them, and I ran into a situation that I don't understand. Let's say I have this query for that updates a tables' values with another ...
1
vote
1answer
48 views

Deleting duplicate rows with condition [duplicate]

I have posted a similar question before, but this one is a little modified. I have a table with 4 columns as shown below. ITEMCHARGE CPT4 EFF_DATE CPT4MOD 326.8 29075 ...
5
votes
2answers
131 views

T-SQL brain teaser: find non-overlapping sets

I would like to ask for help coming up with a query, which can identify groups on non-overlapping records. Here is a sample scenario (admittedly contrived). Let's say I have employees who are ...
0
votes
1answer
23 views

optimizing a select query of 1.5 million entry

I have the following query: SELECT s0_.id, s0_.lowresimageurl FROM app_instagram_shop_picture s0_ FORCE INDEX ( idx_deleted_shopId ) LEFT JOIN app_instagram_shop s1_ ON s0_.shop_id = s1_.id AND ( ...
-1
votes
1answer
34 views

How to manage two tables in SQL Server [closed]

i have two tables offer1 and offer2 The two tables are Offer1 Offer2ID|OfferName|OfferExpiryDate Offer2 Offer2ID|OfferName|OfferExpiryDate now i have third table which keeps record ...
1
vote
2answers
50 views

Deleting duplicate rows with condition(Using SQL and LINQ)

I have a table with 5 columnsID,CPT4,CPT4Mod,ItemCharge,Eff_Date. Deletion Condition: When rows exists with duplicate CPT4and CPT4Mod field values but different ItemCharge and Eff_Date values, ...
1
vote
1answer
25 views

How to Select the First (or last) entry for a specific day

I have a table "AttendanceRecords" with entries like this EntryID UUID PRIMARY KEY, StafID UUID REFERENCES staffmembers(ID) NOT NULL, ArrivalTime TIMESTAMP NOT NULL, DepartureTime TIMESTAMP For one ...
0
votes
1answer
19 views

How can I aggregate multiple results from another table using something like BOOL_AND?

I'm using PostgreSQL as my database. CREATE TABLE users ( id SERIAL NOT NULL, name TEXT NOT NULL, PRIMARY KEY (id), UNIQUE (name) ); CREATE TABLE groups ( id ...
0
votes
2answers
15 views

SQL Query Help to get Quiz statistics

I'm coding a quiz web application and i need help. I've got three tables Nicknames : |USER_ID|NICKNAME| that stores USER_ID(auto increment) and NICKNAME registered to my system. Questions : ...
0
votes
0answers
15 views

Sub queries in Apache Hive

I have a table with following structure col1 col2 col3 col4 category 300 200 100 20 1 200 100 30 300 2 400 100 100 70 1 100 30 200 100 ...
0
votes
2answers
41 views

insert inserted id to another table

Here's the scenario: create table a ( id serial primary key, val text ); create table b ( id serial primary key, a_id integer references a(id) ); create rule a_inserted as on insert to a do ...
1
vote
1answer
31 views

Performance of single vs multiple column unique constraint

I'm using PostgreSQL 9.3. I want to understand if I have an option to make a constraint unique across the entire table vs. unique across a subset of the table (i.e. by using 2 columns in the unique ...
3
votes
2answers
64 views

New Index on table cause table to be locked really often

Here are my tables : CREATE TABLE [dbo].[Trackers] ( [IdTracker] INT IDENTITY (1, 1) NOT NULL, [IMEI] NVARCHAR (16) NULL, [CreationDate] ...
0
votes
1answer
29 views

Need help in incrementing the date in oracle

Error thrown as "Invalid number" while trying to increment the date. Given below is the query executed through sqlplus. Please help me on this. select ''''||to_date(:To_date, 'dd-mon-yyyy')+1||'''' ...
6
votes
2answers
173 views

Why doesn't a delete increase unused space in a table?

If I populate the following table: IF OBJECT_ID ('dbo.CleanTableTest', 'U') IS NOT NULL DROP TABLE dbo.CleanTableTest; GO CREATE TABLE dbo.CleanTableTest (FileName nvarchar(4000), ...
0
votes
1answer
40 views

Turning multiple fields in column to row

I have an issue that has really stumped me in SQL Server. I have recently had the need to insert a row in to a table, made up from a number of columns. I want to make the one row up from something ...
1
vote
2answers
45 views

New to databases - does my ERD reflect good database design?

I'm making a database to hold data for a media player that I'm working on. Originally, I thought to use one table with the fields: {filePath,artist,title,album,track_number,length,date,artworkUrl} ...
0
votes
0answers
61 views

Oracle - Slow queries without prepending schema name or providing hint

I am logged in as the schema owner in Oracle 11gR2 on Linux. I have 55 million rows in table. select max(col) from table; - takes 300 seconds (index full scan) select max(col) from schema.table; - ...
-3
votes
1answer
15 views

Query required to get data from same column [closed]

I trying get data from table having customer colums and details column details columns having several values like, Pen,Pencil, notepad,Pins etc. I want to query customer having pen and pencil. Pls ...
0
votes
0answers
10 views

PostgreSQL query slow when using tsvector and ORDER BY despite having index

Running on a large database (around 1.5G) The following query takes about 70 seconds to run, SELECT x FROM DBText x WHERE x.status = 2 AND x.publishedTime < 4574590406397 AND x.service = ...
0
votes
1answer
31 views

Oracle SQL Statement alter index and add partition

I have an index in which I have to remove one column and reindex back for rebuild: ALTER INDEX <index_name> REBUILD; Is it possible to add partition when I rebuild an index. Partition will ...
0
votes
0answers
20 views

Advice on MYSQL DELETE on CASCADE, UPDATE on CASCADE features

I have 2 tables called copyrigihtinfo and sourceinfo and many to many to relationship table cp_src_junction with following data. copyrightinfo table cp_pk cp_info 1 copyright (c) 1991-2000, ...
0
votes
0answers
22 views

Stored Procedure Issue in Simple Select Statement

Here is my Fiddle Here is My Table : CREATE TABLE IF NOT EXISTS `vehicle` ( `AutoID` int(11) NOT NULL AUTO_INCREMENT, `VehicleCode` varchar(20) NOT NULL, `NumberSeats` int(3) NOT NULL, ...
-3
votes
0answers
41 views

sql query self outer join [closed]

I have one table name lease there is field lsid,month,amount the lsid is every month same suppose like this lsid lsmonth amount 1 30-nov-2014 50 1 31-oct-2014 100 2 ...
0
votes
1answer
30 views

How to delete row from table later than date?

I have a simple table: MyTable: -Id int primary key -Name varchar(MAX) -Deleted bit Now i want delete rows created later that 15.12.2014. But how can you see i don't have a any date columns in my ...
0
votes
0answers
14 views

In Forward Engineering I have an error called 'table does not exist'

This is my forward engineering code. -- MySQL Workbench Forward Engineering SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, ...
0
votes
0answers
28 views

My database engine cannot see one of the drives

I installed SQL Server 2012 on a VM that has two harddrives, C and E. I can log into the Database Engine, but when I attempt to attach a database that is on E, Drive E is not available. Only Drive C ...
0
votes
0answers
26 views

Query plan reads vs statistics io reads

I have a very strange problem. When I run a query with SET STATISTICS IO ON, it shows that I had a total of 183 reads. But when I look at the query plan dmv it shows I did 555,132 reads. I cleared the ...
0
votes
1answer
17 views

storing query results in a variable in mysql and using it in another query

I have a following query which runs perfectly fine: SELECT count(*) as total,l.state as state FROM db1.table1 cd inner join db2.table2 l ON ...
0
votes
1answer
28 views

How can I create a bool column for a view based on the result of a statement?

I'm using PostgreSQL as my database. CREATE TABLE groups ( id SERIAL NOT NULL, name TEXT NOT NULL, PRIMARY KEY (id), UNIQUE (name) ); CREATE TABLE users ( id ...
0
votes
0answers
5 views

Can MySQL Index Merge an Composite index with a single column index?

I am tuning a query and currently have an index as following : Index 1 : (col1, col2) An example query would be : SELECT * FROM t1 WHERE col1 = '1' AND col3 = '2'; I have created an index on ...
2
votes
1answer
39 views

Get products of category plus all child categories till leaf nodes

We have a hierarchy which looks this: Now the problem is that most products are only connected with 1 category, which is most of the time the lowest level. I am trying to get ALL products below a ...