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
2answers
29 views

How to select only those records that have different/multiple for a particular field

Below is an example of my membership table. There some records having multiple values in the email field. I only want to select those records that have multiple email values: Member table ID ...
1
vote
1answer
23 views

Unexpected results with soundex() function when combined st_distance()

select soundex(A.name), A.gid, A.name, soundex(B.name), B.gid, B.name, st_distance(B.the_geom,A.the_geom) * 111.325 as dist from (select name, ...
1
vote
1answer
45 views

Full text search on multiple joined tables

I'm trying to set up a full text search in PostgreSQL but coming across the problem that the more tables I join to the query the fewer the results I get back. The tables I am trying to join are: ...
1
vote
3answers
58 views

SSIS: How to check if a record DOESN'T exist in flat file but exists on the database

I am working on preparing an SSIS job where I am importing a .CVSV file to OLE DB destination (sql database). We are going to get these files on daily basis. The .CSV file contains records of doctors. ...
1
vote
1answer
40 views

Mysql trough access

EDIT I solved the half, that i made a pass through query, so now I only need this: (Licenszek.verz_id)=[Forms]![Hasznalat]![verzio]; to be implemented To the pass trough, ot be the passtrough and a ...
1
vote
1answer
23 views

Rename PK column names when they are FK in another tables

I need to change the names on PK columns and that has relations with another tables meaning they are FK also so this is what I am doing: SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET ...
1
vote
1answer
49 views

Replace Yes with 1 and No with 0

I get a data set and an example of the field is below. The values if these fields is "Yes" or "No". I would like to replace the value of "Yes" with 1 and the value of "No" with 0. This file will be ...
1
vote
1answer
37 views

How to update row values with values from SELECT into another DB in a trigger

I have been working in a trigger for INSERT|UPDATE values for a given record based on same PK. What trigger basically should do it is, foreach row when some INSERT happens on veeva_new.account: ...
1
vote
1answer
30 views

Can I remove “/*!50100 PARTITION BY HASH…” to success with import?

I'm trying to import a database and get this message (Swedish lang phpMyadmin): As you see, I get the message: #1064 - You have an error in your SQL syntax; check the manual that corresponds ...
1
vote
1answer
18 views

Named Parameter Markers in DB2 for z/OS

I have a query where I will be using the same value twice for one of the parameters. This query will be run under IBM Data Studio to see the results. Below is a sample query: SELECT * FROM ...
1
vote
1answer
32 views

Update query could not be bound

I'm trying to do a simple update query and I'm getting this error: The multi part identifier "customers.customer_name" could not be bound Query: Update Suppliers Set City = (select s.city ...
1
vote
1answer
23 views

Update reps table with right values in a trigger after insert on userterritory

I two DBs veeva and pdone as shown below in the pics As you can see veeva is simple and hasn't no constraints which relies on duplicate and wrong values. The problem happen exactly on ...
1
vote
1answer
35 views

how to avoid duplicate record with certain conditon

Heading ##I have a table with data like below +----+--------+-----------+----------------+ | id | name | testfield | status | +----+--------+-----------+----------------+ | 1 | raju | ...
1
vote
2answers
60 views

sql join with laravel query builder

I have a transactions table with the following field: Transactions ID | amount | branch_id | supplier_id 1 | 1,200 | 2 | 1 Subsidiary ID | Name | Type 1 | supplier1 | 0 2 | ...
1
vote
1answer
19 views

Trigger is failing with no errors at all, why?

I need to UPDATE territory_id column at pdone.reps table by using and filtering results from veeva_new.userterritory so based on the answer I got here I am trying to build my own and this is how it ...
1
vote
1answer
44 views

Update records from one table to another in different databases where condition is accomplish

I have two tables stored in two differents DBs and I need to perform some sync between both tables based on lastmodifieddate and lastSyncAt. Let's call them as db1 and db2. This is the DDL schema for ...
1
vote
1answer
33 views

default constraint issue

I have a table say tempTable with one column having a default constraint ALTER TABLE [dbo].[TempTable] ADD CONSTRAINT [DF_TempTable_Version] DEFAULT ((1)) FOR [Version] Version decimal (18,1) ...
1
vote
1answer
42 views

Alter of stored procedure and execution performance

I would like to understand how an alter of a stored procedure without modifications can impact performance. I had a situation where a production environment had its database schema updated and a ...
1
vote
2answers
35 views

Select data where column value exists in seperate rows for same reference id

This is on a MySQL database. Locations have services. What I want is to get all results where service_id is 2 AND 3, not OR so using IN is out I believe. Database ---------------------------- | ...
1
vote
1answer
25 views

Select Distinct on subset of columns, name different set of columns to return

I am using PostgreSQL and have two tables: Table_A colA | colB | colC | colD | colE | colF | colG | colH | colI | colJ Table_B colA | colB | colC | columnD | colE | columnF | colG | colH | colI | ...
1
vote
5answers
89 views

TSQL insert table using view — performance issue

I have a big view joining multiple tables that in a regular basis materialists itself into a table (this step occurs for viz's tool read a table instead of a view during data source refresh): select ...
1
vote
1answer
16 views

JDBC prepared statement - make a token null

So, I have an insert statement in a Java program I'm writing. Under some conditions, I want it to insert some values as null. However, before I can execute the statement, I have to set all of the ...
1
vote
1answer
37 views

SQL Server Query For Getting data in Specific Format

We have two tables. One is PriceGroupTable and other is PricesTable. There is a one-to-many relationship between them. Please refer to the attached pic for more details. I am looking for a SQL ...
1
vote
1answer
14 views

Join tables up together to get different counts of account type per postcode are

I am trying to deterine the amount of account types per postcode range. I have the following code that works but I would like help in refactoring it as only 1 line of code changing between each ...
1
vote
1answer
20 views

Union of data from all tables with name containing a substring

I have 500+ tables all containing a column called COLUMNDATA. The table names are like: TABLE_FIRST, TABLE_SECOND, ... ,TABLE_FIVE_HUNDREDTH. What I am trying to get is a column containing all the ...
1
vote
1answer
38 views

generate new column from another table column, treating nulls are unique

I have a table that looks like the following: |device_id | login_id | ----------------------- | 1 | NULL | | 2 | A | | 3 | A | | 4 ...
1
vote
1answer
22 views

UPDATE with Nested Query

This is what i've tried UPDATE (SELECT * FROM music GROUP BY songalbum) SET albumID = (SELECT albumID FROM albumList GROUP BY album ) WHERE songalbum = albumList.album this give the error #1248 ...
1
vote
1answer
29 views

Problem passing rows results to columns names

I have a table with following data: ID IDALUMNO ALUMNO IDTIPOEVALUACION TIPOEVALUACION NOTA 1 682 ALVITEZ MIRANDA, KAREN LIZET 1 PR1 ...
1
vote
1answer
45 views

select members with the longest running absence streak

I have a database containing a table that stores attendance data, and its columns are member_id and datetime_attended. And another table storing members info, which is made up by the columns id and ...
1
vote
1answer
41 views

Returning case-sensitive input of case-insensitive array match

Taking a JSON table with some simple data: CREATE TABLE jsonthings(d JSONB NOT NULL); INSERT INTO jsonthings(d) VALUES('{"id":1,"email":"Test1@test.com"}'); INSERT INTO jsonthings(d) ...
1
vote
1answer
77 views

Optimizing a query that performs worse on a smaller dataset

I am trying to run this query. The * is just for simplification, I'm selecting ~10 specific fields for some calculations. SELECT * FROM `orders` LEFT JOIN `orders_processed` ON ...
1
vote
1answer
31 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. ...
1
vote
1answer
58 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 ...
1
vote
1answer
37 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 ...
1
vote
2answers
54 views

Repeating rows of date intervals based on another table in Oracle

I have a table of maintenance plans with date intervals between each required maintenance period. Fiddle: http://sqlfiddle.com/#!4/af742 create table maint_sched (maint_id number, start_date date, ...
1
vote
1answer
94 views

Group by maximum consecutive row

I have data like the following: id | src_ip | dst_ip | port | ----|----------------|--------------|------| 256 | 192.168.61.200 | 10.75.64.222 | 80 | 257 | 192.168.61.200 | ...
1
vote
1answer
25 views

making a where clause optional in a sql statement

Here is my current query: `SELECT `performers`.`hash`, `performers`.`alias`, `performers`.`date_updated`, `performers`.`status`, IF(`performers`.`status` = 'active', 'deleted','active') AS ...
1
vote
2answers
537 views

Whats SQL Server NVARCHAR(max) equivalent in MySQL?

Using SQL Server you just have to give the "MAX" parameter to the length of a text data type, but in MySQL there's no such a thing. According to Ispirer: "n" is the maximum number of characters, ...
1
vote
1answer
74 views

How do relations work in NOSQL? [closed]

I was using SQL in all my previous application and to understand the Parse.com db storage, I wanted to know NOSQL. I tried searching the differences between SQL and NOSQL for past 2 days & I ...
1
vote
1answer
23 views

Formatting SQL Source Code in SSMS [closed]

There are several source code formatters for SQL in SSMS. I have tried a couple and found that are not configurable in terms of what formatting they do (e.g. indenting). Does anyone know of one ...
1
vote
1answer
137 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 ...
1
vote
1answer
127 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
vote
1answer
30 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
1answer
83 views

db schema for a object with multiple foreign key tables

I have a question table which contains question_id, question_text and choice_type_id ( say freetext, binary choice and multiple choices ) Now, the question table (which has question_id, ...
1
vote
1answer
112 views

A query for merging date intervals

I have a simple table with 3 columns: (cid, from, to) -> (int, datetime, datetime) The difference between dateFrom and dateTo should be >= 1 month. And unfortunately i have some corrupt data ...
1
vote
1answer
46 views

Add multiples of rows till they satisfy an arbitrary sum then return the rows that do

Am not sure if this is possible. Let's say I have an arbitrary figure like 200, I have a table with two columns (both ints). Lets call the columns col_a and col_b. I need to perform one query such ...
1
vote
3answers
166 views

Distinct Random select

Hi can anyone help with this little MS SQL Puzzle. I basically need to get a 1 random answer from each of the submitters. id, submitter, answer 1, James, Blue 2, James, Red ...
1
vote
1answer
43 views

Is there a way to get disc space remaining using an SQL query on an Oracle database?

We experienced a problem recently where the disc space ran low and some queries started giving unpredictable results. The root cause was that we'd take too many restore points and filled up the disc. ...
1
vote
1answer
42 views

Finding the current prices for n Fuelstations at a certain point in time

I have a Table where price information is stored in with approx 13 million rows stored in a PostgreSQL 9.5 database. CREATE TABLE public.de_tt_priceinfo ( id integer NOT NULL DEFAULT ...
1
vote
1answer
77 views

SSIS Transaction Problem

I am trying to use SQL transaction with my SSIS package so if any error comes changes are rollback. I am using an "Sequence Container" in Control Flow for this and setting its "Transaction Option" to ...