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
17 views

Groups relationships - Detailed or Direct?

I have a Person model: PersonId Name ----------- ---------------- 1 Jessica 2 Jennifer Then I have a ShareModel which have the Personand an ...
-1
votes
2answers
35 views

Query to get the listener.ora path in Oracle 11G

Can anyone help me out with an PL/SQL query to get the path of the listener.ora file in Oracle 11G? I require it to be fetched from the Oracle DB only via an SQL query & not via the Operating ...
1
vote
1answer
65 views

How to join SQL tables where value is Between min and max value

I am currently looking to join two tables together based on an IP and IP range. Both the IP and Range are currently stored as BIGINT. For example we have a table MasterData with IPs in integer ...
0
votes
2answers
33 views

how to make shapefile in geometry column of ms sql?

I was tried ogr2ogr command like this. ogr2ogr -f "ESRI Shapefile" "C:\temp\sqlexport.shp" "MSSQL:server=[RemoteServerIp];database=[dbname];User Id=[user];Password=[password];trust_connection=yes;" ...
0
votes
2answers
28 views

Transform 14 columns into 2 (SQL Server 2008) - Pivot/Cursor not helping

After hours googling pivot and cursors. I couldn't think or figure out how to do this. I have this query: declare @banco varchar(100) set @banco = 'CascVW' declare @tbltemp1 table ( ...
-3
votes
2answers
42 views

How work SELECT in database [closed]

My table has 8,400 rows of user information. Say I submit the query SELECT name FROM users WHERE name = 'jhon'; I know that 'jhon' is the 400th row in my dataset. My question is, will the DBMS ...
0
votes
2answers
78 views

Executing sp in ssms much faster than executing in job step

My stored procedure takes 23 secs in ssms but takes 4 minutes when exec via job. Can you please help me in finding out. Below is SP code ALTER procedure [ops].[trailers_sitting_builder_mod] --WITH ...
0
votes
1answer
26 views

Behaviour of Bulk Insert in pgsql or any Database

I'm using PostgreSQL 9.2.4. I'm working with multiple tables with large number of data. I have two tables Table_One which has one of the field with varchar(250) and Table_Two with one of the field ...
0
votes
1answer
34 views

SQL problem with checking next and previous rows

I have a list and the returned table looks like this. I took the preview of only one car but there are many more. What I need to do now is check that the current KM value is larger then the ...
0
votes
1answer
34 views

Retrieve user id for users that have 5 specific rows

I have 2 tables: Titles and Data They have a One-to-One relationship The entry_id in Titles t = entry_id in Data d I need to retrieve the t.author_id for those users who have 5 specific rows in the ...
-1
votes
2answers
87 views

SQL: put a space between two strings (string concatenation, adding strings) [closed]

I have a table fname Mname lname mark joy smith joy warner I want to print mark joy smith jay warner using only SQL and not a function.
-1
votes
2answers
225 views

Why is “select join insert” so much faster than “loop insert”?

MySQL docs state that the time required for inserts has these approximate proportions: Connecting: (3) Sending query to server: (2) Parsing query: (2) Inserting row: (1 × size of row) ...
0
votes
1answer
50 views

How can I choose the best autogrowth option for my new database? [duplicate]

I want to create a new database that I can use for testing, restoring it from a full backup from a production database. These backup file sizes are around 45,486KB, and the production database size is ...
0
votes
1answer
86 views

MySQL table doesn't exist

What I did before the disaster was: vi /etc/my.cfg I added innodb_buffer_pool_size=4G innodb_buffer_pool_instance=2 innodb_read_io_threads=12 innodb_write_io_threads=12 innodb_io_capacity=300 ...
-1
votes
1answer
73 views

Is SQL injection a neccesary feature? [closed]

[EDIT] Is there a technical case for a protocol which supports SQL commands that can be hijacked by their own arguments?[/EDIT] From my understanding SQL injection exists because it is possible to ...
5
votes
1answer
242 views

Get specific result without using loop

I've a table in which data is like this for single user ID - Number - SubNumber - Name 1 101 201101 Jack 2 101 201102 Jack 3 101 201103 Jack 4 101 ...
0
votes
1answer
40 views

Add '%' sign to MySQL results

I am using a query to calculate total percentage but I want a '%' symbol to appear next to it. Any ideas that could help me My query so far is SELECT student.StudentID, student.Name, ROUND ...
0
votes
1answer
46 views

SQL update next row in select

I have ran into a problem with SQL. I have a list with car and mileage data. What I need to do is for the empty fields to calculate data. Each row has a field for KM (mileage in KM metric unit), ...
0
votes
1answer
49 views

Query MongoDB collection and find rows from 7 days ago

I have a MongoDB collection called messages and this is an example document for that collection: { "_id": { "$oid": "551943eee4c6acf40fe5a0f2" }, "sender_id": { "$oid": ...
0
votes
2answers
49 views

Duplicate sequence of rows

I have a history table (EnrollmentHistory) used to track changes to another table (Enrollment) in my database. The EnrollmentHistory table is populated by a trigger that fires whenever a change is ...
0
votes
0answers
38 views

How do I modify an access query to select a row based on one column when other column information is not distinct?

I have three main tables in Access 2007 that I query to get the Class, Skills, and Students. Mutliple other tables are included in the query to pull other information. If a person learned the same ...
0
votes
2answers
43 views

Get rows where lastLoginTimestamp is in last 7 days

I'm trying to get the rows from a table where lastLoginTimestamp is in last 7 days and I'm doing as follow: SELECT * FROM representative WHERE DATE_SUB(lastLoginTimestamp, INTERVAL 7 DAY) ...
2
votes
1answer
43 views

Select multiple rows based on date interval from two fields

I am still learning SQL and I would like to do something that I dont know if it is possible. I have a table in which each record has a initial date and a final date. I would like to create I query ...
-1
votes
1answer
59 views

Replace SQL Server with another DBMS [closed]

In our current application (C#, ASP.NET) we are using SQL Server database. My superiors are planning to move from SQL Server to another database considering the amount of investment involved with ever ...
0
votes
3answers
97 views

MySQL - How do I Calculate an Average Value Over a Period of Time When Only Value Changes are Recorded

I am tracking the sales price of various items, and I would like to calculate the average price of each item over a period of time. My simplified tables look like this: Items ------------------ |key ...
0
votes
1answer
89 views

Automate SQL Server restore from Prod to Dev

I would like to setup an automated restore job which takes the latest timestamp .bak file and restores it into the DEV instance. I currently have a job on the DEV box that uses the UNC path to the ...
0
votes
1answer
41 views

SQL queries failing, Memory not releasing

I have a SQL Server 2008 R2 with 8GB of ram and SQL Server is limited to 6GB. It seems to not be releasing the memory its used, and at some point future queries begin to fail. This is a mirrored ...
-4
votes
1answer
39 views

From keyword not found? [closed]

SET ECHO ON SET HEADING OFF SET FEEDBACK OFF SELECT * FROM GLOBAL_NAME; CREATE TABLE CAR(REGO CHAR(8) NOT NULL, MAKE VARCHAR(20) NOT NULL, CONSTRAINT CAR_PKEY PRIMARY KEY("REGO")); INSERT INTO CAR ...
3
votes
1answer
93 views

SQL Server index causing incorrect behavior on cursors

I have a SQL Cursor that's behaving incorrectly as soon as we added an index to a table. Here's a trimmed-down example of the query causing issue: DECLARE @CUR_CRDATE NVARCHAR(8) DECLARE ...
0
votes
0answers
42 views

Query that return comma separated list of tuple

For example I have these two table: Table user_score: user_id/ tag_id / score 1 100 0.5 1 200 0.2 1 300 0.3 Table place_tag_count: place_id / tag_id / ...
4
votes
3answers
108 views

Scalable query for running counts of events within x previous days

I already posted this question on stackoverflow but I thought that I might get a better answer here. I have a table storing millions of events occurring to users: ...
0
votes
1answer
42 views

GRANT permission to access to respective creator

Does the following command: GRANT SELECT ON EVENT TO STUDENT; grant student access to whole EVENT table? If yes, how to only give STUDENT access to EVENT(s) record created by respective STUDENT?
0
votes
1answer
31 views

IS-A relation when defining tables

I already asked this question on SO, prior to realizing that there may have been a more suitable place. I am trying to implement an IS-A relationship between tables. Say I have a singer and a band ...
0
votes
1answer
117 views

SQL CHANGE DATE FORMAT IN BULK

I have a database with several hundred fields but my data structure is wrong. It is currently in uk format as follows: d/m/y 01/01/85 01/01/96 23/12/87 What would be the most efficient way to change ...
0
votes
4answers
54 views

Aggregate data from two tables with different field names

I have two tables that each have date and amount fields. This is for a donation system so one is pledges and the other is donations. Here are the structure of relevant tables and fields: pledges ...
1
vote
1answer
102 views

SQL query to sum a column prior to date and show all entries after that date

I have a database function that sum a column prior to a date and after that date show all entries one by one. that function return the data ordered by a common field and apply the sum by date every ...
2
votes
2answers
147 views

Check if contiguous date interval exists

I have a table in PostgreSQL which describes some events that have a start date and an end date: CREATE TABLE my_table ( event_id serial NOT NULL, start_date timestamp without time zone NOT ...
0
votes
1answer
104 views

MS Access: adding column if not exist (or try/catch it)

this is an easy question, but I can't find out the solution... I have to check if a column exists and add it if the test is negative. How can I do with only sql code? This is the syntax for SQL ...
0
votes
1answer
34 views

represent multiple entities to one entity relationship

If suppose, I have following tables: Here, person can own either home or car. person can't own both at a time. If person owns home, then owns field will be equal to 1, if it owns car, owns field ...
1
vote
1answer
97 views

How to edit data to 2 tables using MySQL Workbench

How to edit data in 2 tables using MySQL Workbench (or can I)? I use the below query to get the data but unable to edit it from the table (or Form Editor). SELECT * FROM TABLE1 ...
-1
votes
1answer
26 views

How to data transpose in sql view?

Table1 Name CITY RANK Manish New delhi A Akash New delhi A Akash Aligarh B Vinay Barh C I have to transpose like Name New Delhi Aligarh Barh Manish A ...
1
vote
1answer
29 views

Update incoming rows based on % calculation

Below is the business requirement which I have to achieve... As a Sales Data Operations process/product owner, I want to be able to identify share class conversions (aka "wash trades") coded as ...
1
vote
2answers
56 views

Slow Select over View

My simple SELECT statement on a view in Postgres 9.3.1 is pretty slow. The receipts table has 20 million entries and the other one has around 17k. But I still think it should be faster than ~16 ...
0
votes
1answer
32 views

building structure for employee office relation

I have a table defined like this empid fromdate todate office_ID 1 2012-03-01 2014-04-2 1 1 2014-04-03 ---- 2 2 2012-03-01 ...
0
votes
1answer
37 views

Find all tables in a DB with column names that contain that substring?

Say I have these three columns student_id, name, identify in three different tables in the same database. The query should search for column names that contain that substring. i.e. id should return ...
0
votes
1answer
36 views

detect what columns to select depending on a column value of the same table

I am trying to build a query which returns different columns of the table depending on a column of the same table. Say, a column represents a type of item. This is my temporary solution, in which I ...
7
votes
4answers
398 views

Mathematical equality of two SQL statements

Is there a way to get check the mathematical equality of two SQL statements? I have two SQL statements: SQL_STATEMENT_1 SQL_STATEMENT_2 Running both statements on data and comparing the output ...
0
votes
0answers
27 views

Postgres count of delimited items in bytea encoded string

How would you get a count for each of $ delimited Individuals in each of the group_names? (Example: SomeGroup has 1, This Is Another Group has 8) thedb=# select group_name,encode(group_data,'escape') ...
1
vote
1answer
60 views

Rebuild vs Reorganize [duplicate]

I currently have a maintenance plan that is reorganizing indexes everyday and I would like to know if you reorganize an index everyday would you ever need to rebuild the index? If so, why?
0
votes
1answer
178 views

SQL Query - Possibly the most poorly written query in the history of mankind

Having a major headache trying to tune this query and looking for help, a programmer who had no idea what they were doing messed with this query and it is currently being used in production and it ...