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 ...

0
votes
1answer
16 views

How to get data from Select tag and Insert into Input tag using ASP.NET

Right now I have a Select Tag retrieving all the Title of the documents from the Database: string QueryString = "SELECT TITLE FROM DOC"; SqlConnection myconnection = new SqlConnection(...
0
votes
3answers
26 views

For Each Display on Same Row SQL Server

I am trying to create a single row that includes an Assembly number and each component. I have a table called Assembly with a Unique Identifier that can be tied back to the inv_mast table as well as ...
0
votes
2answers
19 views

Return one result for each search value

How can I return a unique value based on a set of non unique values being searched? For example: If I wanted to return one phone number for a list of 4 people who can have more than one phone number ...
0
votes
0answers
10 views

Merge same SQL database values in table and relating table

sure it could solved one by one, for each value in specified column but I was looking for an more elegant way, handled by one SQL query. Following mini database: Two material tables: Table MatA: ...
0
votes
1answer
14 views

Copy Database table data to text file without looping recordset

Is it possible to get the result set data to single string (for writing to notepad)? Using record set we need to loop through each fields. Is there any other way we can get to a single string without ...
0
votes
2answers
15 views

How to increment a column value by 1 for selected rows in postgres?

I have a postgres table which contains the columns id, name, item and counter.Now I want to increment the counter value by 1 for those rows that the user belongs to. I tried doing something like this ...
0
votes
2answers
19 views

increment in update query adds 2 in table instead of 1

I have a news detail page where i am updating the 'views' field by 1 when the page is browsed. query is as followed: $conn->query("update TABLE set views=views+1 where ID='$id'"); Its increment ...
0
votes
0answers
20 views

Getting invalid parameter marker on db2 query with additional bound value

I have a php script where I'm executing some PDO statements and everything's been working until now. I recently added the sg.group_code as group_code into my first select, binding it as one of my ...
0
votes
1answer
15 views

ORALCE PL\SQL: best practice to count rows to prove feedback before use them

i'm current locking for the best way to count the number of rows i'm gonna use for some calculus before trully use them. The reason is that i need to prove feedback like "analyzed 1/100 rows", "...
0
votes
3answers
40 views

SQL Server - Manipulate data and return new results

Is anyway to do something in SQL Server to manipulate data like manipulating arrays in any other programming language? I have one SQL query that returns 3 columns, "dt_ref" (date), "vlr_venda" (float)...
0
votes
3answers
16 views

Tuning the below query

Can the below query be tuned? Can i write it without using minus operator ( SELECT table_owner || '.' || table_name AS table_name FROM all_tab_modifications WHERE timestamp >= SYSDATE - 80 ...
0
votes
0answers
10 views

Data To Export Contacts Into Different Columns

I have 2 tables one stores Retailers info (Store Name, Address, Post Code) I then have a Contact table that stores personal details Name, Telephone, Email Address. I'm exporting data, but because I ...
1
vote
3answers
22 views

Getting first instance of a date from otherwise identical rows in SQL

I have a table in which there are multiple rows that are essentially identical, except for a timestamp. There will be many permutations of a, b, and c, but I need only the earliest timestamp of them. ...
1
vote
1answer
18 views

Table Lock SQL Server 2 sessions

i have a doubt about the table locks on sql server. For example, i have one table: RowN RowText ---------------- 1 Row1 2 Row2 3 Row3 In session 1 i need to update the table, ...
0
votes
1answer
29 views

getting syntax error on creating function

I'm trying to create a function like the following: CREATE FUNCTION TitleToFileName(title varchar(200)) RETURNS varchar(200) BEGIN set title = REPLACE(title,":"," "); set title=REPLACE(...
0
votes
0answers
14 views

Convert PDF File to binary encoded string and store into SQL Server without using BULK

I need to read a PDF file and convert that into Binary string into SQL server but I cannot use BULK operation , I cant not use the below code any alternative to BULK DECLARE @pdf VARBINARY(MAX) ...
0
votes
1answer
19 views

Django from Python VS SQL for making database

Basically do you guys know which one would it be better to use between Django and SQL for database? And in terms of effectivity which one would be better?
0
votes
0answers
42 views

SQL - Check each column of database to find value?

How do I go through each column of my MySQL database to return the value of a column if it is like a given variable? e.g. database: username | password | column1 | column2 | column3 | column 4 |...
2
votes
7answers
44 views

Based on the value in one column change the value in another column across group

I am new to SQL Server, kindly help I have a table: Group id DEPT marks -------------------------------------- A 001 CS P A 002 ECE ...
0
votes
2answers
26 views

How to select non-integers (varchars) that possibly have leading zeros?

I have a table (let's call it MYTABLE) and within MYTABLE I have a column identity_number, but this number is stored as a string (that's the way it is, I can not change this, because I am not the ...
-1
votes
0answers
25 views

Get column names if value is true

Say I have table: table_name: animal column_names: "dog": 'f', "cat": 'f', "cow": 't' . . . How can I display the column name "cow" ? Thanks!
1
vote
2answers
15 views

Attempting to unpivot

I'm attempting to unpivot a table I have previously created and pivoted and get the error: ORA-00904: : invalid identifier 00904. 00000 - "%s: invalid identifier" *Cause: *Action: Error at Line: ...
0
votes
0answers
18 views

Efficiently keep audit trail

We have an application developed in ASP.Net MVC 5 (database is SQL Server). We have three different entities that uses the app. For example let's say there is a webapp for a school where the main app ...
0
votes
2answers
35 views

sql (oracle) count and sum within the same select/where query

With reference to the following and correctly answered question: sql (oracle) counting number of overlapping intervals Given the following table test in an oracle sql database: +----+------+-------+-...
1
vote
2answers
45 views

SQL Replace date in string

I have a string file name that are not always the same and I'm struggling to come up with something clean and not too cubersome that will strip out the date portion of the sting and replace it with ...
0
votes
2answers
29 views

SQL - distinct number of elements in the row

Let’s say I have three columns: dim1, dim2, dim3 - all of int type values. I want to calculate the number of distinct values in the row - so in case for row of ID #13 dim1=20, dim2=30 and dim3=20, ...
-1
votes
0answers
15 views

multiple line input of one query to Output of another in oracle

I have a perl script in which we are using sql query at 2 places. the first query produces the table name. it gives around 100 tables names. then we are applying loop and passsing table name one by ...
4
votes
3answers
48 views

Max() Over Partition By with date conditions

How do I get the following result in yellow? I want to find the maximum score over the previous year (excluding the current date) and partition by Name1 and Parent1 I've tried the following which ...
0
votes
1answer
23 views

Datetime conversion error in SSIS from US date format

I've got an issue with my SSIS dataflow. I'm extracting data from SalesForce Marketing Cloud. In one of the data extensions, there's a date field (in US format). The problem is that when the data is ...
0
votes
2answers
24 views

How get product id that contains in two terms category type and group type

How get product id that contains in two terms category type and group type I have one table ec_terms and ec_terms_product How I can get product IDs that contains both alias best-offers and premium-...
-1
votes
0answers
25 views

CONNECT BY explanation

I've never used the connect by nocycle or connect_by_root. Can anyone explain what this query is doing? Thanks. SELECT Pt_ID, MdID, FLAG_1, MIN(START_DATE) AS START_DATE, MAX(...
0
votes
1answer
48 views

How to show results as a percentage with SQL?

I am trying to complete some exercises where I must show how many products cost above 20 as a percentage of the total. I can easily show the products that cost above 20 but I am not sure how to answer ...
0
votes
1answer
17 views

count posts one category in CodeIgniter

I have problems with count posts a cateory and show them. I want show categories in sidbar and count of them base on posts. for example. num=count of posts that have medical is 8 medical=8 My ...
-2
votes
0answers
36 views

Is it possible to concatinate variables for use inside a foreach loop

Im am trying to create a single page to show 1 of 17 tables that are recalled form the database upon request, to be able to give the user the option of looking at the results/schedule week by week. ...
1
vote
2answers
35 views

SQL convert array column to rows with old keys in arrays

I have a table in PostgreSQL, with two columns: id and nodes. id is of type bigint, as it is the primary key in the table. nodes is an array of bigint. I would like to create a new table, where the ...
-1
votes
0answers
19 views

How to migrate a database that has a database master key and certificate for encryption [migrated]

Morning y'all. I'm a little stumped at this one. We have a database that we encrypted a column in a table. This is the master key that I created and the Certificate & Symmetric key. I need to ...
-2
votes
4answers
31 views

Ignore parentheses in MYSQL Like query

I have a sample MYSQL table with the following rows: name ------ Oppo A71 (2018) Plum Flipper (2018) Lenovo K5 Note (2018) Huawei Y9 (2018) Huawei Y7 (2018) I want to let the user search through the ...
1
vote
2answers
40 views

MS Acess: Union and transpose multiple tables

I have a number of static tables with numerous columns. They all have one common column. I would like to transpose each of these tables so that the column names become rows, the column values become ...
-1
votes
1answer
6 views

The MERGE statement attempted to UPDATE or DELETE the same row more than once. This happens when a target row matches more than one source row.

I am using the same script for multiple servers. Its working fine for all the servers but not working for a particular server. Everything is the same for all the servers. Any help will be appreciated
0
votes
1answer
18 views

Update date on datetime field without losing the format

I have a table with two columns: M_OP_DATE (of type DATE) and M__DT_UTC_DATE (of type TIMESTAMP(3)). The table contains data as follows: +---------------------+---------------------+ | ...
1
vote
2answers
50 views

SQL trouble! IF/CASE help required

So. Rearranging column format in a table to import into some software. There's a gender column in the previous DB that contains either M, F or U. The new software won't take U as a valid value, so I ...
-5
votes
0answers
36 views

Need help to write dynamic sql query

It is necessary to enter data in different input tables according to the reference table. To do this, you need to pull out from the input tables all data that does not match the standard and put them ...
0
votes
2answers
43 views

how to use group by function in the condition?

my inner query is working well but when i use group by function i am getting an error "Column 'b.id' is invalid in the select list because it is not contained in either an aggregate function or the ...
-1
votes
2answers
19 views

Combining multiple sub-queries into a single query

I'm attempting to combine several sub queries to form a report detailing order in an 'In Progress' status. Long story short there are multiple stages an order goes through and the client wants to get ...
0
votes
1answer
36 views

need to get description of id from another table which are pipe separated

I have two tables table1 and table2 in table1 there is a column with name typeids in which ids are pipe separated ex: 2|3|4 --> these ids are the primary key in table2 table2 contains Id, ...
0
votes
0answers
44 views

How to check that a value is NOT IN a %ROWTYPE from an SQL statement

Im writing a PLSQL stored procedure. Note that the below is only a part of it and the actual SP is complex than this. All I want to know is that in my nested query below, how i can check a certain ...
4
votes
1answer
50 views

How to optimize a 2 table query where data can be only discriminated based on both tables?

I have the following 2 tables and data distribution: drop table if exists line; drop table if exists header; create table header (header_id serial primary key, type character); create table line (...
-2
votes
2answers
38 views

Select with date

I select Registered_Date in my database like below : Select Count(Registered_Date) AS DATE from Patient_Records where Registered_Date >= '09-01-2018' and I have (3) of '09-25-2018' on my ...
0
votes
2answers
17 views

SQL count a value for each userID record except where one record value of userId is x

I got so stuck I do now know how to formulate my question so I created a hypothetical scenario with my wanted result. I am trying to create a query that counts the amount of fruits per userID exept ...
-2
votes
1answer
40 views

Mysql select - performance drop after adding second join

Following SELECT worked fine until I added second LEFT JOIN. Now the time to display table is 18s. It works fine with both JOINS when I ommit group_concat and GROUP BY. Creating of view didn't help. ...