Questions tagged [sql]

Structured Query Language (SQL) is a language for querying databases. Questions should include code examples, table structure, sample data, and a tag for the DBMS implementation (e.g. MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, etc.) being used. If your question relates solely to a specific DBMS (uses specific extensions/features), use that DBMS's tag instead. Answers to questions tagged with SQL should use ISO/IEC standard SQL.

Filter by
Sorted by
Tagged with
0
votes
1answer
10 views

How to build query where 2 fields are inter dependent in MSSQL

I am new to the world of SQL queries, I am comfortable writing basic sql queries limited to to CRUD operations. I am now working on a project where I have to write complex queries and I am seeking ...
0
votes
0answers
6 views

How to find the column causes the error on Azure Data Factory?

{ "errorCode": "2200", "message": "Failure happened on 'Sink' side. 'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=The given value of type String from the ...
0
votes
0answers
5 views

I have to get the path of the file from user's system to call in the batch file?

this is my Batch file.. @ECHO OFF sqlcmd -S.\SQLEXPRESS -i C:\Users\Administrator\Desktop\Script.sql exit Actually i'm not clear that where will user paste the Script.sql file in his system when I'...
-1
votes
1answer
12 views

Dynamic arrangement of SQL pivoted columns

My Data - CREATE TABLE Tbl1 (State varchar(max), Value int) INSERT INTO Tbl1 VALUES ('A',10), ('B',20), ('C1',30), ('C3',40), ('D',50), ('C2',70), ('E',60); Scenario/Problem - I want any state ...
0
votes
0answers
23 views

How to return IQueryable from an SQL expression?

I am getting the following error trying to query from my database using C#: LINQ to Entities does not recognize the method 'MyProject.Models.DB.Department getDepartment()' method, and this method ...
0
votes
1answer
12 views

How to retrieve a Character for a boolean field in SQL 2005

I am trying to retrieve data from a 2005 version of SQL Server. The program that is calling the Stored Procedure if populating a datagridview in VB 2008. One of the fields coming back is a Boolean ...
-1
votes
0answers
19 views

How to create a RESTful API from a “View” in SQL server with C#?

My company does not allow me to create a new "Table" in an existing SQL server. Rather, I was only provided with a "View" in a database that shows the data from different tables through some queries. ...
0
votes
0answers
12 views

What database should I use?

I need two databases in my project. Namely, I would like the first database to store products and information about them (macroelements per 100g and calories). I would like any user to personally add ...
1
vote
1answer
27 views

Select rows where all children contain same value only and no other scenario

I am writing a query to select all rows where all children contain same value only and no other scenario. Tried many examples online, nothing matching. select * from table where all children ...
0
votes
0answers
24 views

Subquery returns more than 1 row in SELECT part(Dlookup to MySql)

I am migrating a desktop application from MS Access VBA to Java Springboot application and I need to make a VBA query work in MySQL. The VBA query is insanely big so I present to you a smaller example ...
1
vote
2answers
26 views

Join 2 Tables with if conditions using MYSQL Query

I have 2 tables: users and prov_spec_search. Am looking for an sql query to join these tables with the following conditions: users Table: id | first_name | last_name | activ_status ------------------...
0
votes
0answers
14 views

Trying to validate information based on security rights

Trying to make certain textboxes on my webpage visible based on the rights a user has from a user rights table I have Here's my stored procedure being called ALTER PROCEDURE [dbo].[...
0
votes
0answers
10 views

How to show duplicate name in a column to match data in another column using XML PATH

I have a column with one to three courses, that needs to match one to three professors. A student has two classes with the same professor, and two with another professor. The data needs to match in ...
0
votes
2answers
22 views

How to get total number of ads, clicks and views by referrer

I have the following query: select AD_ID,to_char(adate,'YYYY-MM-DD') DT,upper(referrer) REFERRER, 'NOT TRACKED' SOURCE, sum(views) VIEWS, sum(clicks) CLICKS from ( select ad_id,adate,...
1
vote
0answers
31 views

Calculate Time from Database

I am trying to make my program calculate a break time with data stored in an mysql database. private void timerpause_Tick(object sender, EventArgs e) { MySqlConnection conn = ...
1
vote
0answers
19 views

problem with the regression query in googles batch prediction table in bigquery

i am using google cloud platform to make predictions on some tables. i have gone though all the steps to do this but now on the last step i am stuck. i have a prediction table from my trained table ...
0
votes
1answer
26 views

Find diff between three tables

I'm trying to find the difference between three tables, a, b, and c. I'd like to join all three, showing nulls where each table does not have records. Each table has two columns that I would like to ...
0
votes
1answer
22 views

Merging rows in MySQL with null values on same timestamp

I have a query that is returning all of the data that I want but with a lot of extra null values because of how the case statements execute. I am trying to get rid of all of the null values just have ...
0
votes
2answers
33 views

Select the first duplicated element

I have 2 Classes in JAVA ( MODEL1 && MODEL2 ) As you can see here : MODEL1_ID ACTN_DTE MODEL2_ID ---------- --------- -------------- 1 14/11/19 18 1000 14/11/...
-2
votes
0answers
15 views

how to send incoming sms to database

any database . the database info to be retrieved
0
votes
0answers
15 views

SQL Create Table by OrderID & Product Code between Ship & Return Date w Wkly Revenue

Lo Folks o/ I apologize if I've titled this incorrectly or my terminology may be lacking as I am self-taught in writing SQL data queries; however, I am stuck on how to create one to produce data I ...
-1
votes
1answer
18 views

How to match and fill based on first record in SQL?

Currently have this table here: i have two columns a URL which constantly changes and a url code - I want to take the first URL record and "fill" a new column where the URL_code matches - see outcome ...
-1
votes
0answers
13 views

SQL splitting column string and searching [duplicate]

I am writing a search function for a website I'm building, so far so good until I hit this roadblock. I have tags stored in a column like so: c_id c_tags 1 Tag1,Tag3,Tag5 2 Tag3,...
1
vote
2answers
30 views

Looping through a CURSOR in PL/PGSQL without locking the table

I have a simple PL/PGSQL block Postgres 9.5 that loops over records in a table and conditionally updates some of the records. Here's a simplified example: DO $$ DECLARE -- Define a cursor to ...
0
votes
2answers
24 views

PATINDEX Number/range of wildcard characters

In regex we have syntax for occurrence of any characters between 'a' and 'b' that goes like this: /a.{5,15}b/ but we were able to specify minimum of characters between them (5) and maximum (15). Is ...
0
votes
0answers
21 views

Spring CrudRepository return group by result as a Map

I use CrudRepository to execute a native query, where i use a sum and a group by. I want the query to return the result as a (Hash)Map. My query looks like this: @Query(value = "SELECT l.currency, ...
0
votes
0answers
13 views

Table Normalization, Attributes that have no dependencies

Hi this is my first time posting so sorry if formatting is bad. I have a question regarding normalization, I came across a problem in homework and I am having issues finding any information on it. ...
0
votes
0answers
24 views

SimpleJdbcCall exception: Required input parameter is missing

I need to use withoutProcedureColumnMetaDataAccess(); method in SimpleJdbcCall to avoid unnecessary calls for meta date and in order to use it, I need to declare parameters. One of the parameter is ...
0
votes
1answer
25 views

INFORMATION_SCHEMA: can this be used to find all the same named columns in all tables in same database

I've been handed a new database with over 500 tables. Can I use the INFORMATION_SCHEMA to execute a query to list all the tables and identify those same named columns across all the tables within the ...
-2
votes
2answers
38 views

add new column if the previous one is not null

I need to create sqlite statement that checks if a specific column value is not null then add a new column and insert the new value. What I already have is this : CREATE TABLE "StuPayment" ( "...
0
votes
2answers
21 views

Check for Lowercased First Character in String Value for MariaDB

In my MariaDB environment I want to check to see if there are any values in the table "contacts" and the column "firstname", where the first letter in the string value is lower case. My question is: ...
0
votes
0answers
34 views

how to optimise a query request in postgreSql

This request take 99 minutes to be executed I need the some result given when I exceute it, I try to use index and materialised view but this can not optimise it: select min(pointage_materiel....
1
vote
4answers
47 views

How to return next year values when you're in the current year, but keep current values when you switch to next year? which becomes current year

I have a view that runs a user selects a certain month. It returns various values based on a month selection. Using MS SQL Server Problem: It returns those values based on the month and it works as ...
0
votes
2answers
23 views

Use few analyzers in GIN index in Postgres

I want to create GIN index for Postges full text search and I would like to ask is it possible if I store analyzer name for each row in table in separate column called lang, use it to create GIN index ...
0
votes
2answers
28 views

Find all tables with a specific column name + where value is lower than X

I need help in searching our database. So we have this problem that we need to know all tables, with the column_name "sysmodified" and see if there are any entries before a specific date (25-sep-2019)....
-1
votes
2answers
37 views

ORACLE SQL group by dates that are off by a day

I am trying to group by dates that are off by one day. EX: 02/19/2019 and 2/20/2019 would be grouped together. For context, I am using this within a group by statement. Is it possible to use ...
0
votes
1answer
20 views

ORA-00904: “ROW_ID”: invalid identifier

I wanted to get the rowId from the below query, but when i execute the query i get an error. Can any one please help. WITH DATA_TBL AS (SELECT /*+ parallel(scr,10) ...
0
votes
1answer
31 views

Search across multiple columns and get the best match

I have a database table similar to this: +------------------+-----------------+------------+-----------------+ | businessname | street | city | country | +-----------------...
1
vote
0answers
20 views

Django ORM Group By Date Range

I've got a Django Model where users can be assigned a status for a specific period, e.g. 'Absent' from 2019-10-01 to 2019-10-20: class Status(models.Model): user = models.ForeignKey(User, ...
0
votes
0answers
26 views

TypeError: Object of type bytes is not JSON serializable with pd.read_sql

Not sure why i get the following error: TypeError: Object of type bytes is not JSON serializable when i run the below.. any ideas? import pyodbc conn = pyodbc.connect('Driver={SQL Server ...
1
vote
1answer
25 views

How to handle precision problems of floating point numbers?

I am using Firebird 3.0.4 (both in Windows and Linux) and I have the following procedure that clearly demonstrates my problem with floating point numbers, and that also demonstrates a possible ...
0
votes
2answers
22 views

Live sql oracle integrity constraint error, primary key not found

fairly new to sql not sure why this error is coming up, i'm asked to use alter to add columns and foreign key to the animal table referencing the species table species name. i can't figure out a way ...
0
votes
1answer
35 views

Can I select from a #temp table to define the @query attribute to dbmail?

I'm getting an error when I try to attach a query as an attachment for an email. The query pulls from a temp table. The email works just fine without the attachment. I've tried adding in @...
0
votes
1answer
19 views

Revoke Multiple Users in Oracle Developer

I want to remove a role from a list of users based on a select statement. My select statement works fine, but when I try to implement the revoke statement I get "missing or invalid privilege". I am ...
1
vote
3answers
29 views

calculate min distance of each shop's location sql query

I have a table which contains X,Y Coordinates of each shop. I want to find min distance with each other. I mean nearest shop. For Ex: (Desired Output) Shop_ID Nearest_Shop_ID Shop_1 ...
-2
votes
2answers
49 views

SQL Query Join 4 tables

I am New In SQL I want to write query to get a Report. Employee (EmployeeID,EmployeeName) Job(EmployeeID(Foreign Key),JobEndDate(Nullable)) Files (FileID,FileName) EmployeeFilling (EmployeeID(...
0
votes
3answers
40 views

Postgresql select where one of two columns in set

My tables : R1(id serial, a int , b int) - 100k records R2(id,serial,VAL unique) - 40k records Indexes : r2(VAL),r1(a),r1(b) My goal : get all records from R1 where a or b equals VAL in R2 I ...
0
votes
0answers
18 views

A complicated VLOOKUP scenario that needs to run through BigQuery because of it's size

I managed to write code for the other SQL queries but this one seems to complicated for my current level of expertise. On this sheet ( https://docs.google.com/spreadsheets/d/1gnHcTc-...
0
votes
1answer
15 views

Filter dynamic e-commerce in PHP

Post table is products list, post_feature is the features of the products, The image of the posts table: enter image description here The image of the posts features: enter image description here ...
0
votes
1answer
26 views

SQL query column alias name with concat does not work

If I try to add alias name to a column name when using sql concat along with html tags it fails with error. Please find below the details. 1) CountryDtls Table Id |CountryName |CityName | ---|-----...