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

learn more… | top users | synonyms (2)

0
votes
1answer
23 views

WSFC File Share Witness

I've got a multi-site 2008 R2 WSFC with a file share witness. I noticed that the possible owners for the FSW is every node in the cluster. I thought the concept of a FSW was that no node of the ...
3
votes
3answers
47 views

How to Pivot in PostgreSQL

Having the following data in a table: ID Category Value 1234 Cat01 V001 1234 Cat02 V002 1234 Cat03 V003 1234 Cat03 V004 1234 Cat03 V005 I want to have the ...
1
vote
2answers
54 views

How to get the PC models with identical speed?

I am trying to get pairs of PC models with identical speeds and the same RAM capacity. Each resulting pair should be displayed only once, i.e. (i, j) but not (j, i). Result required as : model with ...
1
vote
0answers
50 views

I have a query challenge for anyone willing to participate [closed]

I have a table with fields x, y and bit. x and y are integers and bit is a boolean, zero or one. I would like to write a query that generates a table where the fields of the table are the values of x ...
0
votes
0answers
42 views

MySQL apostrophes suddenly handled differently

I have 2 production servers with exact same MySQL version (mysql Ver 14.14 Distrib 5.6.26-74.0, for Linux (x86_64) using 6.0). In one, a stored procedure continues to run properly off of a ...
0
votes
1answer
74 views

Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '*%text%*4' to data type int

I have a database that holds information linking customer data to forms that are filled out by them, or on them by someone else. Our UI runs reports but can only run 1 form at a time. I am trying to ...
1
vote
1answer
53 views

PostgreSQL 9.5: Permission to deny functions body

I create new role without any grants. New user can't select on tables, but can see functions body (pl/PgSQL) I want permissions for new role: allow INSERT into one table. deny see tables, ...
1
vote
2answers
54 views

Script/tool to use to check when the server is not being heavily used and configuring backup on Availbility Groups

If I were to backup 50 databases in SQL server, I want to make sure that backup is taking place when the server is not that busy. Is there any way or script/tool to use to check when the server is ...
0
votes
3answers
49 views

How to select mutiple values with like clause

SELECT * from table WHERE column LIKE "AAA%" OR column LIKE "BBB%" OR column LIKE "CCC%" I have more than 10 values to select, so it is not appropriate to write like the above example. Is ...
0
votes
1answer
54 views

open/execute huge sql file

I have SQL file using PostgreSQL with size about 7GB. How can I open/execute the SQL file? I have researched and tried using navicat premium,razor SQL, HeidiSQL, workbench. In all I get out of memory. ...
0
votes
2answers
66 views

How to count specific products?

I have a table product and its columns are maker, type and model. I want to get the makers who produce 6 product types and more than one model. Here is something I am trying: select maker, type from ...
0
votes
1answer
27 views

how to count specific product in sql table

I have a table product and its fields are maker, type and model I want to get the makers who produce only one product type and more than one model. Here is something I am trying select count(distinct ...
1
vote
2answers
103 views

Converting rows to columns

I have data like following: created_at | status ---------------------+------------- 2016-04-05 1:27:15 | info 2016-04-05 3:27:15 | info 2016-04-05 5:27:15 | warn 2016-04-05 ...
0
votes
1answer
37 views

Creating a pseudo email database

I am creating a database for Job offers website between Employer and Applicants that required sending Email between the two in MSSQL. Let's say I have 3 tables like these: Employer ID int ...
2
votes
1answer
24 views

How to count multiple values of a column as one group? [duplicate]

I have a table main with the following rows: id | name | rank ----+--------+------ 1 | Ali | a 2 | Sami | b 3 | Khan | c 4 | Kamran | d 5 | Imran | e 6 | Asad | a 7 | ...
0
votes
0answers
26 views

How can I create a user that can only create databases and users?

What I want is a user (#1) that can create other users and databases (#2, #3, n). To clarify, user #1 should NOT be able to manipulate any databases. Even the ones created by himself. Users (#2, #3, ...
0
votes
1answer
21 views

Aggregate function to count occurrences of specific word

I have a table upon which I'm performing a GROUP BY statement. One of the columns in my table can contain one of 5 different words (essentially an enumerated type). Is there a way I can use an ...
0
votes
0answers
29 views

How do I clear Oracle SQL history list?

I am using Oracle Database Express Edition 10g. I want to clear the history list as shown in the image below. Is there a SQL command that clears the history that saves the SQL queries. Thanks
1
vote
1answer
39 views

Exclude All Matching Rows

I have a table that has a unique ID, name, email, and some other fields. I want to match this table against another table on email, but sometimes emails are shared. The unique ID is not shared among ...
0
votes
0answers
34 views

Is there trade off for using FORCESEEK in SQL query?

What is the trade off for using Forceseek vs naturally letting SQL Server decide the execution plan? Is there a possibility that using forceseek invalidates the original query by returning a different ...
0
votes
0answers
11 views

Find missing associations in many to many relationship [duplicate]

I have client and category tables with a many to many relationship via client_category_association. table: client id name 1 ek 2 do table: category id name 1 un 2 dos 3 tres table: ...
0
votes
1answer
51 views

SQL Server Trigger When New Value <> Old Value

I need a trigger that update to Null a column averytime another column is changed. This is what I have now: ALTER TRIGGER [dbo].[ERROR_CLEAR] ON [dbo].[contact] AFTER UPDATE AS BEGIN SET NOCOUNT ON; ...
0
votes
1answer
47 views

using triggers to synchronize data

i've two database, Database1 and Database2! i'd like to synchronize data from the specific table of Database1 to Database2 whenever Database1 updates. I've used triggers to synchronise data and it ...
1
vote
1answer
35 views

SQL Error: OA-12991 - Unable to Drop a Column after removing all referenced Multi-Column constraints

I am new to Oracle DB and am in need of some help. I would like to drop a specific column but i am getting a specific error. The issue specifically is: SQL Error: ORA-12991: column is reference ...
0
votes
2answers
112 views

How to optimize this SQL Server query?

Anyone have any suggestions for how to optimize this query? Running SQL Server 2008.. The object is to look at accounts that were created yesterday, compare their email addresses and phone numbers ...
1
vote
1answer
18 views

Selecting a id from a pivot table

Trying to make a messaging system, similar to FB, people can message more than one person, when they do it creates a row for the user with the conversation id and user_id in conversation_user. ...
1
vote
0answers
24 views

MySql Error 1451 [closed]

I am by no means a database professional, but I've come here to get some help from people who may understand what's going wrong with my database. The error occurs on this line: update team set ...
0
votes
1answer
17 views

mySQL Event Help - Update colum value for each row every 15 minutes

Okay so if I have a login database: id | email | pass | attempts ---------------------------- 1 | "" | "" | 4 2 | "" | "" | 2 Attempts marks the number of attempts made at logging ...
3
votes
0answers
51 views

What is the difference between a field and a column? [duplicate]

Although I have always regarded the terms as interchangeable, I have read somewhere that they’re not the same. I suppose this means that a record is not exactly the same as a row either. I teach that ...
-1
votes
1answer
34 views

I run the script and it freezes me but varchar(max) and nvarchar(max) -1 always the ones with throws. How max turns -1 [closed]

ALTER FUNCTION [dbo].[get_logtable_script] (@table_name varchar(max)) RETURNS varchar(max) AS BEGIN declare @sql varchar(5000) declare @column_name varchar(max), @data_type varchar(max), ...
0
votes
1answer
24 views

Performing group by, Order by on a table starting from particular date to recent last date [closed]

Am sorry if this question sounds so dumb, please help. I currently use the below MS SQL query to get the list of volunteers on each date and it works perfectly fine, select Date, count(id) as co ...
1
vote
2answers
55 views

Delete rows from a table with inner join conditions

I have a query that selects data from a table based on some inner joins: select * from table1 p inner join table2 e on e.col1='YU' and e.username=p.username inner join table3 d on p.col2=d.col3 and ...
0
votes
1answer
48 views

Duplicate all stored procedures with a new name

I want to take all stored procedures and create them under a new name. My problem is with procedures that are called from other procedures . To rename a procedure is no problem for me. But to ...
2
votes
2answers
62 views

Deleting multiple rows based on the first instance of the value

I have a table with the below structure. I would like to delete all of the records that records that match ColA for any of the ColB's that have a ColC that has an even-numbered value. But only for the ...
2
votes
1answer
40 views

How to join at least two tables with different column names but same data, and only show the matching data

I am trying to combine two (possibly more) tables that has different column names but the same data within the columns I am trying to line up. For example, I have a table called dbo.member and within ...
1
vote
2answers
41 views

UPDATE from subquery updates rows that shouldn't be updated

Using PostgreSQL, I want to update a column. The information how to update is in another table. My try was this, but it also updates rows I don't want to update: update table_1 set column_x = ( ...
-1
votes
1answer
55 views

How to search a given date value in all tables of present in database

I need a query to search for a particular date 2017-04-01 in every table in my database. My database has many tables and I don't know in which table this value 2017-04-01 exists. Please suggest a ...
0
votes
2answers
45 views

need help joining two tables with a having count clause

I am a network guy so I apologize for this.... I have two tables I need to join and pull names out of. pt_basic has the patient names and codes I need, ptc_diagnosis has their diagnosis. I need to ...
0
votes
1answer
27 views

TSQL LDAP query via Linked Server

I have strange problem, I have 3 SQL Server 2012 with Sp1 instances, and on all of them, the versions are identical. I am trying to query Active Directory services, on 2 of them this is working ...
3
votes
2answers
73 views

UPSERT with ON CONFLICT using values from source table in the UPDATE part

Given: CREATE TABLE A ( PK_A INT8 NOT NULL, A INT8, PRIMARY KEY (PK_A) ); CREATE TABLE B ( PK_B INT8 NOT NULL, B INT8, PRIMARY KEY (PK_B) ); This query: insert into table_b (pk_b, b) select ...
1
vote
1answer
47 views

How do I calculate a field based on multiple non-numeric records

I have a several tables that I have joined together to get raw data. Some information about my query in the most basic form: Table1 has a column [FacilityID] that is a unique identifier in that ...
1
vote
1answer
45 views

Relationships mess

Say I have a table ads, and each ad has several medias - held in a medias table. Each media can be one of several types. Types are in a media_types table. So, for example, an ad has two medias: one ...
1
vote
1answer
27 views

MySQL: How to perform aggregate functions on rows where a column is duplicate, for all values of said column

I have a table where one of the columns may have duplicate entries, and I want to condense each set of duplicates into a single row, with an aggregate function applied to the other columns. I cannot ...
0
votes
0answers
10 views

Send SQL Server Snapshot to External FTP Server

I am trying to set up Snapshot-Replication for SQL Server 2014. I need Server 1, the publisher and distributor, to create a Snapshot and FTP to an external FTP server i.e. FTP server is not hosted on ...
2
votes
1answer
52 views

Grouping data by year based on two timestamp columns

My data table has the following columns: id INTEGER, name TEXT, created TIMESTAMP, deleted TIMESTAMP I want to product a report of the count of each name (which can appear several times in the ...
0
votes
1answer
40 views

One table with 2 foreign key mapping same primary key

SELECT status, schedule_switch.Switch_Employee_ID, schedule_switch.Requesting_Employee_ID, employee_info.FirstName, DATE_FORMAT(schedule_switch.date, '%m-%d-%Y') AS switchdate, ...
2
votes
1answer
86 views

Joining 2 queries to match Months side by side

I have 2 SQL statements that I want to join up. The first gets the actual data per month for Turnover accounts. The second query gets budgets (if any) for the same Turnover accounts. Query 1 Actuals ...
1
vote
2answers
25 views

Microsoft SQL Replication

Good day, I know very little about this topic and need some advice on where to start. I have two Microsoft SQL production databases that I would like to replicate so that I can run my reporting on ...
2
votes
2answers
218 views

Incorrect syntax generating XML

I am trying to run below code in SQL server 2000 SP4 but getting error. Declare @Body varchar(8000); Declare @TableHead varchar(8000); Declare @TableTail varchar(8000); Set NoCount On; Set ...
0
votes
2answers
53 views

How to create an insert trigger?

This is 1/4 of an overall assignment and I need help with this part. The assignment question: Create a trigger on the Rental table that will check when a new rental is to be inserted, that the ...