I just started studying SQL queries. I am practicing on this site: https://www.techonthenet.com/sql/joins_try_sql.php I want to find: “the name of the employee with the highest salary for every department”. My query is: And I get null value for first_name : I understand that the problem is due to …
Is it possible to perform multiple replacements in one function call?
If you want to replace multiple strings in one go, you can of course nest the REPLACE function, eg. like this: SELECT REPLACE(REPLACE(REPLACE(foo, ‘apple’, ‘fruit’), ‘banana’, ‘fruit’), ‘lettuce’, ‘…
Athena geospatial SQL joins never complete
A very basic geospatial join, based on this example, times out every time. The table polygons contains 340K polygons, while points contains 5K rows with latitude/longitude pairs (and an ID). Both are single .csv files in S3. Query: The SQL query above never completes in the default 30-minute Athena query time…
How can I optimise COUNT with GROUPBY mysql query?
I have 5M records in eus table and 121 records in es table. I am doing a left join but the COUNT query is making my query very slow. How can I optimize this? public static function …
Laravel skip results if they are found in previous query
I’m querying my DB twice to get some items into the header of the page and some bellow the header. I want to avoid duplicates in these two queries, currently I do this by adding a skip method to …
Updating a column based off records from two tables matching?
We’re using SQL Server 2016. I have two tables, DEAD and QUETABLE. However, QUETABLE also has a column called DEAD. This is going to sound confusing, but I’ll try to make it make sense. What I need to …
java.sql.SQLException: Column Index out of range
i need a help when i execute the following MYSQL command in Navicat i get mysql> SELECT Password FROM workers; +———-+ | Password | +———-+ | A | | B |…
Sql query did not return all values when using between clause
I have a query : select * from indicatordetails where indicator.month between ‘January’and ‘April’ When I run it it returns no result, but when I use: select * from indicatordetails where indicator….
Change id values of all rows in table STARTING from a specific number
I have 1000 rows in a table.. I’m getting the last and next available id (to start from) $latest_id = (“SELECT * FROM `vehicles` WHERE ID = (SELECT MAX(ID) FROM `vehicles`)”); What I’m trying to …
SQL Server – Delete rows from one side of a JOIN
I have a query that identifies orphaned rows in one table after joining it to another. The query I have for selecting the rows that need to be deleted works fine, and properly selects the rows that …