I have a ecosystems table, which is self-referencing because each ecosystem can have sub-ecosystems. Each ecosystem can also have a score (which represents how healthy the ecosystem is). The columns are (with example data): The full_slug column represents the full path from top-level ecosystem down. It is red…
New to SQL and having issues with Sytnax (VB.NET)
I am fairly new to SQL and databases in general (in an intro class in college right now) and I have run into a little snag. I am building a paid time off tracker for people in my department (they are like children and can’t keep track of their own things with the tools we already have). I currently have
SQL find the 2 highest score for each country
I have two tables: maps_query and map_time like below: The question is to find the 2 highest score for each country. Desired output is like below: I was trying to use row_number() over but don’t know how to complete the query. Answer This can be achieved by rank() instead of row_number(). A good referen…
Hibernate – make id value be able to be autogenerated directly in datasource as well
I’m making a Spring boot application with Hibernate ORM framework. I have an @Entity class in my code: I successfully can persist a Thing to my datasource. And thing_id is generated as expected. But I cannot insert a record directly in database manager (e.g. DataGrip): I have a warning and appropriate e…
Insert columns into new table where one of the columns doesn’t allow null values
I am attempting to insert 50 rows at a time from one table into another, however I am unable to bypass the ‘Not Null’ column in the table I am attempting to INSERT INTO. Please note I am not able to alter that column so it accepts nulls. I have 2 tables (table 1 and table 2). I am inserting
How do you make your check constraint case insensitive in SQL?
This is my piece of code. I want to be able to insert values in lower case too. Example down Below: But I can edit my check constraints to add ‘Web Site’ or ‘Catalog’, I just want to try something else. Thanks. Answer You may lowercase the column and then compare to lowercase string li…
SQL CHECK() how to check if input is numeric value?
Hey how can I check if the input has 5 numbers? I tried everything like isnumeric/LIKE ‘%[0-9]%’ they all not working… I tried the following but it doesn’t work.. please help Answer You can use GLOB operator: See the demo.
Prepared Statement does not use expected index
I have a very large table of IOT sample that I’m trying to run a relativly simple query against. Running the query normally using the MySql CLI returns a result in ~0.07 seconds. If I first prepare …
Converting timestamp from one column of an SQL table to dates in another column of the same table
I’d like to convert unix timestamps from one column of an existing sql table to dates in another column of the same table. Something like this: take the values of column TIMESTAMP from every raw and convert it into a date and put it into column DATE. I already figure out that the below expression conver…
Bulk insert data into empty (but existing) records with SQL
The first table columns (A to G) are already filled with data for each row/record, but the columns H to K have no data in it yet. So I have to add data for these columns, for each individual row in the table (1 to 285, whatever the number is). Columns A to G should remain unaltered! What SQL query