Let us say, I want to find the second highest salary. For that I use the following query. However, I want this to return null when the table only contains one entry, and therefore there is no 2nd highest salary. How can I do that? Answer Use your query with aggregation: The aggregate function max() will retur…
Tag: sql
How to use the COUNT function
I’m trying to set up the best basketball team for fantasy basketball in the 2020-2021 season. I created a database for basketball player’s stats and imported a table that contains projections and draft rankings for this coming season. I’m focusing on players who play in the center position, …
Error: ORA-12154: TNS:could not resolve the connect identifier specified when entering username and password in sql plus
I’m trying to login to my oracle database using sql plus. But such error out ORA-12154: TNS:could not resolve the connect identifier specified here is my tnsnames.ora file, sqlnet.ora file and …
How can you assign a value to a variable if mysql does not yield any result?
There are two databases. I am trying to see if email in the first database is also present in the second database. Here’s the code that I’ve tried: The output is: The type for onera and julian is blank because there email is not present in the phpbb_users database. How can I avoid this blank space…
JpaRepository SQL syntax error when trying to save to MySQL Date
I have the following row in my MySQL Table: https://i.stack.imgur.com/u0FC4.png This column is represented as: And it is bound to a Thymeleaf form like so: Now if I insert a date into the MySQL db directly, the date is loaded and set to the correct date on the form: https://i.stack.imgur.com/e35lr.png But eve…
2 column with 2 different condition in one table
is it possible to create a query that will output 2 column with 2 different WHERE clause this my ideal output: where count 1 is the result of the 1st WHERE clause. Which I already created. What I want is to have another column where in the value will be with different WHERE clause. here’s my query: with…
Oracle SQL Subquery – Usage of NOT EXISTS
I used a query to find a list of Primary Keys. One Primary key per each ForiegnKey in a table by using below query. Let us say this is the result : 1,4,5 NOw I have another table – Table B that has list of all Primary keys. It has 1,2,3,6,7,8,9 I want a write a query using the above
Transpose rows into columns in SQL Server, I try it using pivot but, expected result is not reached
Transpose rows into columns in SQL Server, I try it using pivot but, expected result is not reached, using pivot getting Max value only Expected output: Answer You can use conditional aggregation with row_number():
SQLite Incomplete Time String
I have a table with incomplete time strings, such as ‘0:09.735’ (minutes:seconds.milliseconds). As the function strftime expects certain formats, such as ‘%H:%M:%f’, I have “to complete” the incomplete timestring first. The first strftime function with the complete timestri…
Conditional query with a parameter stored procedure
I’m learning SQL so I don’t know yet all the subtlety of the language, I wrote the following stored procedure (simplified here): But it doesn’t look like a natural way to do that and there is a lot of repeated code. I want to avoid something like But if it’s the only way. I don’t…