I am creating a database to store music. There are different categories that each have sub categories. Example: id name parentID 1 instrumentation null 2 …
Tag: sql
What is the best way to compare a name field with a string value?
I have a query that compares a string value against a name field in my database. The structure of the name field in the DB is not consistent, it could be any of these: John Doe Doe John Doe, John My …
Database Query to generate a Time-based Chart
I have a logins table in the following (simplified) structure: Now I want to generate chart like this: https://prnt.sc/mifz6y Basically I want to show the logins within the past 48 hours. My current query: This works as long as there are entries for every hour. However, if in some hour there were no logins, t…
SQL join condition either A or B but not both A and B
I have sales data by years and quarters and for the last year I want to fill missing quarters with last available value. Say we have source table: +——+———+——-+——–+ | year | …
How to INNER JOIN only one row from second table
I have a issue joining only one row from the second table statement: SELECT ART.*, EAN.* FROM ART,EAN WHERE ART.ARTNR = ean.unit_artnr AND ean.typ = ‘LE4’; TABLE EAN has sometimes 2 …
Search area in Jquery for searching in a grid of input from another input
I wish to search from an input (type=”text”) in a grid (like table but made in .css for be responsive so with div ans span in html) if input (type=”text”). (I precise than this grid in imported from …
Selecting data from 3 linked tables
I have three table review_form_languages, review_form_translations and rate_params. rate_params -> id, label review_form_languages -> id, name review_form_translations -> id, rate_params_id, …
TSQL query with aggregated data
I have a query that returns the min, max, avg and total for two different products. The client however wants the min, max, avg and total combined for both products. However I have an undesired result …
nested join in Db2
Folks, what is wrong with this query i get error stating below in DB2 LUW. [42703][-206] “d.sales” is not valid in the context where it is used.. SQLCODE=-206, SQLSTATE=42703, DRIVER=4.23.42 [56098]…
MySQL – While Exists from a snippet throws error
I was reading through this page https://www.sqlteam.com/articles/more-trees-hierarchies-in-sql (great article on managing hierarchical data in SQL) and following along in MySQL and was trying to run …