Structured Query Language (SQL). For questions about the language, not Microsoft SQL Server (tag sql-server).

learn more… | top users | synonyms (2)

1
vote
1answer
35 views

Need help on UPDATE query [closed]

This is my table tracks id | art | time id is an auto-increment primary key art is a varchar(512) time is a timestamp not null predefined as current_timestamp and on update current_timestamp ...
1
vote
2answers
64 views

Building a where clause based on user selections

My group and I are developing a multi agent system (MAS), a system that is supposed to conduct statistics on specific fields of the agents' databases using semantic search and ontology (the user ...
0
votes
2answers
52 views

Get date based on interval days in sql

I have a table containing range table like this. DayFrom Dayto Frequent 60 46 3 = interval 15 days (15/3 = Every 5 days send email for 3 times) 45 37 3 = interval 9 days (9/3 ...
0
votes
1answer
41 views

on duplicate key update

I'm trying to execute the following statement in MySQL: INSERT IGNORE INTO shop_item_details (shop_id,product_id,product_name,Product_model,Product_category,Product_details,price) VALUES (1, NULL, ...
0
votes
0answers
22 views

Use a Trigger After Insert and Update to Sync Two SQL Server Databases

I am not very familiar with Triggers in SQL Server and need help creating one to sync customer information from one database into another as it is added or updated. To make a long story short I am ...
1
vote
1answer
64 views

Finding interval overlap between two tables

I have two tables that have top_depth, bottom_depth, lith_type. One defines the different layers found in a borehole and the other define where samples are extracted in each of the layers. I would ...
1
vote
2answers
56 views

SQL minimum permissions to manage any job

I am looking for a way to grant minimum rights to a login to manage ANY SQL Server Agent job. The SQLAgentOperatorRole allows to manage own jobs and disable/enable any job, however I need to allow ...
1
vote
1answer
32 views

SQL db2 remove specific item from the query

Can you please help me out with the below query? What I am looking for is a code to exclude items with wording '90003' from column COR_ID. So far I have a code that extracts data with date older than ...
0
votes
1answer
39 views

Flagging duplicates

I have a huge table with a couple of duplicates: I want to add a new column that shows some value when duplicates occur, something like: case when fist.firstname = last.firstname then 'yes' else ...
3
votes
1answer
53 views

Updating multiple columns using Case

I have a query that looks like below: UPDATE some_table SET column_x = CASE WHEN x_specific_condition THEN new_value_for_x ELSE column_x END, column_y = CASE WHEN y_specific_condition THEN ...
1
vote
1answer
50 views

Create dynamic WHERE clause from a JSON field

We have tables like this: people_people ( "id" integer... "attributes" HSTORE ) object_permission ( "permissions" JSON ) An example of an object_permission.permissions is: ...
4
votes
1answer
81 views

How to use COLUMNS_UPDATED to check if any of certain columns are updated?

I have table with 42 columns and a trigger which should do some stuff when 38 of these columns are updated. So, I need to skip the logic if the rest 4 columns are changed. I can use UPDATE() function ...
1
vote
2answers
52 views

PostgreSQL: Calculate balance working backwards from current balance

I have a balances table that stores the current_balance for bank accounts; and a transfers table that contains a row for every transfer to- and from an account (deposits are positive numbers, ...
1
vote
1answer
45 views

SQL DB2 query with where clause

Can you please help me out with the below query? I need to extract from column VAL_DT only items with date older than today's date but this rule should not apply to items that contain the following ...
4
votes
2answers
306 views

Struggling with left join - products

I got a quite easy question for you. I have a table products [ID,Name,Category,Price] and a table product_client[ID,product_ID,client_ID] The products table contains all the products of ...
1
vote
1answer
69 views

Awful performance on joined queries while great separately

I have a simple queries: SELECT t1.[IntField], CONVERT(varchar,t1.[KhDateTimeField],121) AS 'TDateTimeField' , t1.[FloatField1], t1.[FloatField2] , t2.[FloatField3] FROM ( SELECT ...
5
votes
1answer
48 views

T-SQL (SQL Server 2012) Update based on lookup table

I have the following tables related to this question: CREATE TABLE tblTitan( titanId int IDENTITY (15483,1) PRIMARY KEY, userId int UNIQUE NOT NULL, titanName varchar(15) NOT NULL, titanExperience ...
1
vote
1answer
31 views

Find common value amongst rows

I have the following table structure with example values: Number Reference Length Quantity ----------- ------------------------- ...
3
votes
3answers
188 views

Two rows into two columns

I have this table: Name Value Sequence ------------------------------- test A1 1 test A2 3 test2 A20 5 ...
4
votes
4answers
146 views

Extract MIN and MAX values related to datetime values on Postgres 9+

I am trying to query a table that has a collection of student grades recorded over time. I would like to produce a result set that grabs the student id, the first grade, first grade date, last grade, ...
1
vote
1answer
31 views

Insert multiples rows/columns - PostgreSQL 9.2

I've got a table that has several columns, But I need to insert data into two columns of that table. I need to add data into those columns, from a select statement. Would it be something like: ...
17
votes
5answers
582 views

SARGable WHERE clause for two date columns

I have what is, to me, an interesting question on SARGability. In this case, it's about using a predicate on the difference between two date columns. Here's the setup: USE [tempdb] SET NOCOUNT ON ...
0
votes
1answer
31 views

Sql Server Security Scenario

I need some advice/help... I need to implement database security in some Databases but I don't know how to do that with this given scenario... Using LDAP Auth We have Table1 In Table1 one we have ...
1
vote
2answers
68 views

Error Updating Record on Table with Partition on a Read-Only Filegroup

We are working to partition our data warehouse (SQL Server 2012 Enterprise): moving old records we don't expect to change to a read-only filegroup on a monthly basis. We're getting errors that records ...
0
votes
1answer
25 views

Teradata Join Syntax

I'm having a hard time doing what I want to do here, as SQL (and Teradata SQL on top of that) is not my main forte. I have two queries that I want to join together. I want everything that returns ...
1
vote
1answer
32 views

Get rows having different values for a column based on the duplicate values of combination of other 3 columns

I want to get only rows having a different values in a column(column name DEF) based on the duplicate rows having unique combination of other 3 columns. Example: In the below example first two rows ...
0
votes
0answers
13 views

How to point View to a dynamic database

I would like to create a view upon a database which changes on time For Example: initially, a view layer is to be created for the database B1_2016 in the next refresh, a new database is created and ...
0
votes
1answer
40 views

INSERT INTO + Selects - PostgreSQL 9.2 [duplicate]

I wanna add some data into two columns in a table. Would be something like: INSERT INTO dm.billables_links (billable_id) VALUES ((SELECT billable_id FROM junk.wm_260_billables2 WHERE info ilike ...
0
votes
0answers
18 views

How to Alias/Display a Column's Row Information

Is it possible to have a row's data be displayed as something else for those who cannot alter the table data? For example, if a column is called "Language_ID" and it shows 2 different numbers like 10 ...
0
votes
0answers
40 views

Query the database for particular value in a column

I have 2 tables which look like this: Table_1: Contains Item Details ------------------------------------------------------ Item_ID | Location | Arrival_Date | Postage_Date | ... ...
1
vote
3answers
74 views

MySQL slow query

This is my first time posting here. I am new to MySQL and trying to learn it as fast as possible but this issue is causing a problem to production and need to reach out for help. This server is ...
0
votes
3answers
25 views

How to insert/combine values from multiple tables?

I have multiple tables (12 for each month) that have 3 columns each ("code", "test_name", "value") Example: January code | test_name | value 0001 name1 17 0002 name2 45 0005 ...
1
vote
1answer
14 views

Deleting data from some but not all tables

I've got a moderately large sql server db for which some data is imported from an external system, and some is entered through the front end or set up when the app is set up. I want to delete all the ...
0
votes
2answers
46 views

Declare variable for SELECT statement in Postgres function

I have modified my function, but I have problems with declaring variables. I use Postgres 8.4. CREATE OR REPLACE FUNCTION requestcounterid(_mindate timestamptz, _maxdate timestamptz) RETURNS TABLE ...
-1
votes
1answer
33 views

Select and Insert for all data - Need help querying [closed]

At a first glance, this is my query INSERT INTO T2 SELECT T1.*, T3.DATETIME, T3.STATEID FROM T1 WHERE T3.DATETIME BETWEEN '01-NOV-15' AND SYSDATE LEFT OUTER JOIN T3 ON ...
1
vote
0answers
23 views

CTE ordering guarantees [duplicate]

I'm starting to make heavy use of CTEs for my postgres based application, and am wondering if selecting from a previous CTE statement guarantees any ordering? E.g. is the order of rows for this query ...
1
vote
1answer
52 views

ORA-01652 : unable to extend temp segment by 128 in tablespace HFDORA_TEMP

I have increased temp tablespace temp02.dbf by the following command alter tablespace HFDORA_TEMP add TEMPFILE '/orac/u01/oradata/hfd2/system/hfd2/temp02.dbf' size 2000M; But after increasing it ...
3
votes
2answers
65 views

Group only certain rows with GROUP BY

Schema I have the following set-up in MySQL database: CREATE TABLE items ( id SERIAL, name VARCHAR(100), group_id INT, price DECIMAL(10,2), KEY items_group_id_idx (group_id), PRIMARY KEY ...
1
vote
0answers
33 views

Accessing a row directly at a table in PostgreSQL by using the PostgreSQL's internal library

I am writing a PostgreSQL extension using the C language. I would like to do the following tasks: Store a set of rowids (or other row identifier, like ctid). Each rowid uniquely represents a row in ...
1
vote
2answers
74 views

Column or global variable ROWNUM not found

I have made an attempt at the ROW_NUMBER(), and when exporting the results in a csv it was worked perfectly. The issue I’m having now is in the where clause to bring back records where ROWNUM = 1. I ...
0
votes
1answer
35 views

postgresql insert from select query, plus static values

Referring to How to insert values into a table from a select query in PostgreSQL?, I would like to INSERT into a table rows from another, specified by a SELECT DISTINCT, plus some static values, ...
3
votes
2answers
889 views

How to check if the table has rows?

I am completely new to PL/SQL. I have written the following PL/SQL script. But it doesn't execute and gives compilation error: set serveroutput on SIZE 1000000; IF EXISTS (select * from my_table) ...
3
votes
0answers
30 views

Should I do the maths within PostgreSQL for ACIDity?

It is my first question on Database Administration Stack Exchange. Please be kind if something is not done the nice way.. I would like to be advised concerning the way I'm working on my database, in ...
1
vote
1answer
36 views

Query using joins [duplicate]

I have the table Vendors (VendorID PK, VendorName, VendorContactFName ,.....) I want to find out the VendorName and VendorContactFName for those Vendors whose Contact First Name is different from The ...
0
votes
0answers
25 views

Postgresql 42883 error code with encrypt function

Ok, the thing is that I'm doing a login controller on my database. Part of it is this function to create users that goes like this: create or replace function crear_usuario(par_usuario ...
0
votes
0answers
54 views

Why my MySQL (myisam) index is broken and how to avoid it?

I have big composite (multiple-column) index on MySQL MyISAM table. And I noticed it doesn't work. I ran SHOW INDEX command. There are NULL in the Cardinality column on the most index fields (except ...
3
votes
0answers
81 views

Export/import data from Excel into a table with queries

I'm a newbie interested in learning and implementing things I learn. I've been working on SQL Server 2014 these days and I'm loving it. I've come across some scenario's where I would have an Excel ...
1
vote
0answers
19 views

Clustered index on last_update_at timestamp

I have a Votes table , which can be considered a wrapper. I have a sub_items table, which holds one votable item. One Vote has many sub_items. On sub_item is owned by only one Vote. I have a ...
1
vote
1answer
62 views

Query to back up a PostgreSQL database

I made a CRUD web application that uses a small PostgreSQL database. It is a donors database with the columns name, telephone, blood type, etc. I have some SELECT and INSERT INTO queries, but now I ...
-1
votes
1answer
20 views

Jobs scheduling to fetch data from multiple servers using SQL Server Agent [closed]

I have 2 servers - server-1 and server-2, both have an identical database. I have scheduled a job on server-1 thru SQL Server Agent (both servers have SQL Server 2005) which will open table1 on ...