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
0answers
12 views

Efficiently implementing pagination in postgres while avoiding duplicates?

Let's say you're making a site like reddit and you want to have infinitely scrolling posts (25 at a time, and 25 more loaded when you reach the bottom) The naive solution uses LIMIT AND OFFSET, but ...
0
votes
2answers
26 views

How to add a tag based on a column value

I'm trying to join two tables and select certain columns to display in the output including a 'flag' if a certain transaction amount is greater than or equal to 100. The flag would return a 1 if it is,...
0
votes
0answers
9 views

(sqlite3.InterfaceError) Error binding parameter 4 - probably unsupported type

I'm not sure which part of the code is giving me the interface error. Any help is appreciated. This is what is being inserted that's not being passed through correctly: [SQL: INSERT INTO minutes (...
0
votes
1answer
26 views

SQL query to find records if and only if join table contains all of a list of values

I have two tables that are joined by an association table. The requirement is to find only records in price table that include all of the menu codes in a list and only those in the list. The data (...
0
votes
1answer
16 views

How to Image Crop And upload to Folder And Save Name in database Using Ajax And Jquery In Php

I want to crop And rezize Image and Upload In Folder For user registration and profile updations.Upload and Crop Image using PHP and jQuery. HTML Form with Image Upload Option with JQuery Croppie ...
1
vote
3answers
24 views

SQL: updating a column in one table based on a count result from another table

I've got a table called GUEST and a table called HOTEL_BOOKING. I want to update a column in the GUEST table called guest_nobookings (this is the number of bookings a guest has made at the hotel). I ...
0
votes
2answers
21 views

Select rows based on duplicates in a column

I want to find all duplicates in a column and display the primary key so I can clean them up. So after a bunch of tutorials I have this which is supposed to work and returns no rows which is great ...
-2
votes
1answer
23 views

How to get the SQL result need?

I need to list the model and manufacturer of all Laptops costing less than 1,000 in SQL. I'm a beginner at this but i have got the first part of what the problem is asking.I have include a picture of ...
0
votes
3answers
24 views

SQL How to SELECT python variable in SQL

Tried something like this cur.execute('SELECT ? FROM translations WHERE imagename = ? ', (target, filename,)) but it just returned [('de',), ('de',), ('de',), ('de',), ('de',), ('de',)] being target ...
0
votes
2answers
21 views

How to select percentage values per group in mysql

I am trying to select percentage values for each group in mySql. I tried to do it in memory, but it is a lot of code to maintain. It would be graceful if I do it via SQL. I am selecting the ...
0
votes
0answers
14 views

Checking the difference between ES and SQL database

I currently have a SQL database of ~250,000 records (with unique ID) and every time a record is added to the database, it's also recorded in ES (with the ID). Each record in the database has a deleted ...
0
votes
0answers
15 views

Created a table with new column names and when executing, an error message stating “Column Name Invalid” appears

I'm trying to add columns (OFFERING_STATUS, SEMESTERS_OFFERED) to this table but when I try to execute the query, it says that the column names are invalid. I don't understand why it would be invalid ...
0
votes
0answers
15 views

query to list product lines of products whose quantity in stock is the least

SELECT ProductLines.productLine, COUNT(quantityInStock) FROM ProductLines JOIN Products USING (productLine) GROUP BY customerName HAVING COUNT(quantityInStock) = (SELECT MIN(...
0
votes
0answers
17 views

How to grab each index using for loop from a list of tuples without interrupting the UI and adding it to a listbox using tkinter?

I am creating a UI using Python Tkinter and I am accessing data from a SQL database. Using this data I want to display it on the UI, and I want to display each index through a 2-second time delay. So ...
1
vote
0answers
16 views

Find an user using its hashed password

I want to fetch an user in the database using its password, that has been hashed using password_hash(). The problem is, this function uses salt so it isn't deterministic. What it means is that I ...
-1
votes
0answers
19 views

how to count row from single column by specific digit stored in mysql in php?

I want to count total number of rows in a specific column by specific digit from mysql database. Suppose I have "RatingTable" and My database structure is: id username rating Now suppose I have ...
0
votes
2answers
18 views

change 2 select joined query to fill with zeros/null instead of filtering out when data does not exist in one query

I have the code below that queries the same table for the value of 2 different tags, and display them side by side (2 columns) when their time stamps match. This has been working ok. However, in some ...
-1
votes
4answers
41 views

How can I switch case for each letter in a string with SQL?

I need to convert this into this using PostgreSQL dxItw9a4 --> DXiTW9A4 Is there any function or way that is already set?
0
votes
3answers
37 views

Is there a way to return multiple unrelated results in an sql query?

I'm trying to create a "feed" system on my site where activity on users' posts is posted. To do this effectively and order all activity by date, I need to put everything in one huge query (unless ...
0
votes
2answers
18 views

Delete records with correlation query in Oracle

I have a table with users and addresses. I need to delete all records from the table where multiple different users are associated with the same address. So, I've prepared the following query: DELETE ...
1
vote
2answers
21 views

Setting rank based on query

I've a table items listing different elements with id, popularity and rank columns. popularity column contains an int allowing to sort elements by popularity. I've made a query to sort by popularity ...
0
votes
1answer
34 views

Identical tables, different performance in SQL Server query

We've been having problems with performance for a SQL Server at work. Queries that run well on one server run awfully on another (e.g. 20 minutes vs 16 hours, same box specs, seemingly same setup). ...
0
votes
1answer
25 views

Error - PLS-00103: Encountered the symbol “SELECT”

I'm trying to create and use a function in a single block of code. The function works fine, but when I try to use a select statement below it oracle gives me an error. The select statement returns ...
0
votes
1answer
22 views

No suitable driver found for jdbc:oracle:thin:@localhost:1521:xe error

I am experiencing the strange problem with No suitable driver found for jdbc:oracle:thin:@localhost:1521:xe when i run JUNIT Test case of any DAO it is inserting fine. But when i run in server it is ...
2
votes
1answer
24 views

oracle sql query for selecting Even number columns

In oracle sql when I am trying to get the output for the below, it is throwing error. select city,id from station where id % 2 = 0; Error: ORA-00911: invalid character 00911. 00000 - "invalid ...
0
votes
0answers
4 views

Realm-js Querying on timeStamp does not work

This is with reference to https://realm.io/docs/javascript/latest/api/tutorial-query-language.html I am not looking for variable substitution syntax as mentioned in the documentation. So i have a ...
0
votes
1answer
36 views

Java + MySQL: Do i have a good way to encrypt a password?

I want to hear your opinion on my following thought of encrypting passwords for my usage. I have a JFrame program which uses a textfield (username) and a passwordfield to "login". I want the password ...
0
votes
3answers
27 views

PostgreSQL: Is it possible to determine if any elements in an array overlap a range?

Let's say I have a table with an int[] column and values: '[1,4,1300]'::int4[] I want to be able to query the column and get a true if ANY of the elements match a BETWEEN statement. So, in this case,...
-2
votes
0answers
21 views

In database sql Why the gpa is not correct here? Gpa have to be right based on total, but all gpa is 0 here

In gpa section all student’s gpa is 0, but it shouldn’t be like this. It should be “if total is 95, it means gpa 4 and letter_ects should be A” But this code is not correct and I don’t know where is ...
0
votes
3answers
39 views

SQL duplicate values of records with multiple joins

My query works fine until I add in the estimate tables, where my data duplicates. Below is my table structure: Jobs | ID | JobNumber | |----|-----------| | 1 | J200 | | 2 | J201 | ...
0
votes
1answer
24 views

How to remove reversed duplicates from my query result?

I solve SQL exercises from Lagunita Stanford and I stopped at Question no.3 (SQL Social-Network Query Exercises). I don't know how to remove reversed duplicates from my query result: Gabriel 9 ...
0
votes
4answers
38 views

How to join two columns from same table and format the new Column in SQL

I am very new to SQL and trying to join two columns from the same table and format the result. The code I have so far is: Select LastName + FirstName as FullName from Customers order by FullName ...
0
votes
2answers
20 views

I have a mysql connection problem, although I connect to the command line with the same parameters

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost:3306/gestionrh"; // Database credentials static final String USER = "...
0
votes
2answers
32 views

Distinct column select and group by multiple columns

I'm attempting to group by visitor_id on a page_views table to count the "visitors" rather than "page view". My schema consists of id visitor_id country_code created_at The following query kind of ...
-1
votes
1answer
25 views

Entity framework does not detect an existing navigation property and attempts to re-add it

I define my model and relation similar to the blob and post example on as on this page. When I have an existing blog and want to add new posts to it, entity framework tries to add a new blog with ...
-1
votes
0answers
13 views

understanding check digit validation [on hold]

I'm not sure if I'm on the correct forum, but I'm very much a beginner and looking for some assistance understanding the logic. I use a system in my work, supplied by a company called Capita and the ...
0
votes
1answer
24 views

Python Invalid parameter type when trying to execute insert query

I'm trying to execute this query however I'm getting the error and I'm using Microsoft SQL Server as database. import urllib.request as urllib import socket import pyodbc from datetime import ...
0
votes
1answer
36 views

Is it possible to select from the result of a subquery in a join

So I have a large subquery and I would like to join on that subquery while using the result of the subquery in the join. For example, I have a table called patient and one called appointment, and I ...
0
votes
2answers
27 views

Sum number by previous row number using select statement

Suppose there are two column name SrNo and Salary i need a third column whose result would show like as below:- SrNo - Salary - Result 1 - 1000 - 1000 2 - 150 - 1150 3 - 200 - 1350 4 ...
0
votes
0answers
30 views

Unable to connect to any of the specified MySQL hosts when I just start to configure

I was starting to learning SQL, then I download MySQL, but I am stuck in this error, I retry again and again but it didn't work still. Beginning configuration step: Starting the server Attempting to ...
-1
votes
0answers
25 views

Error executeDML: ORA-00926: missing VALUES keyword [on hold]

INSERT INTO PATIENTEN(NAAM,ACHTERNAAM,PATIENTID,GEBOORTEDATUM,LENGTE,GEWICHT,TELEFOONNUMMER, NOODNUMMER,ALLERGIEEN)) VALUES ('dennis','7','21-10-2019','190','82','6815','49908','...
0
votes
1answer
15 views

Storing data to SQL not working with my sql connector and scrapy

I am trying to store my scraped data with scrapy to a SQL database but my code does not send anything while no error is mentioned when runned. I am using my sql connector since I don't manage to ...
0
votes
2answers
44 views

How to calculate total wins and losses based on this SQL Table

I have a table called games(game_id, home_id, home_score, away_id, away_score, date) and a table called team(team_id, team_name). I need a SQL query to calculate the total wins and loss and win % (...
1
vote
1answer
23 views

How can I Create Multiple DATEDIFF Columns?

I would like to calculate the DATEDIFF between each of the different ranges represented by the NewValue column below. Id CreatedDate NewValue Count 0 ABC 2018-11-28 09:16:15 ...
-1
votes
3answers
28 views

Issue with SQL join and group

I have 4 tables I am trying to join and then group data. The data consists of jobs, invoices and accounts. I want to generate a total of each account in each job. I have the following tables: Jobs |...
0
votes
2answers
37 views

Is there any way to exec a stored procedure for all selected data rows?

I'm setting up a storekeeping program in which I have 2 tables, one for products and another for materials. In the products table, each product has several materials. Is there any way to select these ...
0
votes
1answer
14 views

How to retrieve the exact response of insert/update statement of Query Explorer SQL Server through python using pymssql

Insert/Update statements always provide updated rows and inserted columns in SQL Server Query Explorer Response Window. Want to retrieve the same results from Python 3.x. I have millions of records ...
0
votes
1answer
19 views

Can I JOIN two tables in different databases with only one match with sum values for each row that repeat in tables in MySQL?

I have 2 databases with product table with ID and quantities like this: db1.products ID Stock 1 10 2 20 3 30 db2.products ID Stock 1 3 2 5 4 40 And need join, sum ...
-1
votes
1answer
15 views

Join three count queries and get results in to three columns

I want to combine three count queries and get results in to separate columns. This is how my data set looks like. I have tried this select id, sum(val = 3) as valcount3 from (select id, s1 as val ...
0
votes
0answers
10 views

How can I add a custom product “Sort by” field in prestashop 1.7.6?

I want to implement a new sort field. In my case it would be the value of a particular feature. In SQL I would solve it this way: SELECT b.value FROM ps_feature_product a, ps_feature_value_lang b ...