Skip to content

Tag: sql

SQL Query – second ID of a list ordered by date and ID

I have a SQL database with a list of Customer IDs CustomerID and invoices, the specific product purchased in each invoice ProductID, the Date and the Income of each invoice . I need to write a query that will retrieve for each product, which was the second customer who made a purchase How do I do that? EDIT: …

How create table with name which name in another table

There is a table in which all the names of the tables are located and I need to create a table with a name from it. I give id to the input of the stored procedure and by this number I need to pull the name from another table result some I need create database schema3.Users. And this table must

Escaped single quote ignored in SELECT clause

Not sure why the escaped single quote doesn’t appear in the SQL output. Initially tried this in Jupyter notebook, but reproduced it in PySpark shell below. Output shows Bobs home instead of Bob’s home Answer Use backslash instead of a single quote to escape a single quote: Alternatively, you can u…

Sql Performance join Vs co-related Subquery

TABLE : employee (id,mid,join_date) Question – Find all employees who joined before their managers Query 1: Query 2: Which of them is correct? If both correct, then how is the performance? Answer They are both correct. Performance questions need to be tested on your data on your system. However, with a …