Ts there a way to extract numbers from a string? In my database there is a column called Reference and it contains multiple numbers CM|319|14163|||109|405000 Is there a way to get the first number like this? select CM|%s|… as ParentId from table So the output should be 319 And maybe even multiple like s…
Trigger to create or update records in another table
Edit: This question is mostly solved. What I am still trying to do might require a different approach. I am adding a trigger to a legacy database table, in order to automatically create new records for a related table. This is not homework. Here is my DB Fiddle on SQL Server 2017. https://dbfiddle.uk/?rdbms=s…
How do I show all records when one field is null in SQL?
I have my code but the @NAME is an optional field for searching. If the @NAME is blank or NULL, it should show all records. How do I approach this? Thanks! Answer There are some ways to do it the easy way. I would do something like this. You can use the Function ISNULL to handle blank or NULL. With
Trying find a better writing for my SQL Query [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year. Improve this question I Have a database of published website pages, with following coulmns: date| publisher_id | pla…
MySQL never completes query with a subquery, but completes when queries are run separately
This is the query that never finishes: When I run just the subquery, it completes in 12ms and returns two ids. When I hardcode those 2 ids in place of the subquery, the outerquery returns two rows and completes in 0.3ms. As you can see, both parts of the query run incredibly quickly and it’s not like we…
Snowflake: SQL Query to identify all the different users with the same ID from the same or multiple tables
There are two tables with both IDs and Usernames. Looking for a snowflake SQL query that results in identifying the IDs shared by different users from the same table or both tables. Table 1 ID User 1001 A 1002 B 1003 C 1002 D 1005 E Table 2 ID User 1006 H 1005 E 1003 G 1002 F 1001 A
How to count the number of entries in the list when requesting Select?
I apologize for the possible incorrectness in the presentation, I use a translator. Let’s say there is a users table in which there is an id field. And there is a list that lists the id numbers and some of them are repeated. My query returns the following 3 – 1, 10 – 1. And I would like to g…
Pulling different rows based on age in select query
Context I am using Oracle SQL and have data that looks like this. People are asked every year what their favorite movie is and that may update from year to year. Person Date_of_Birth …
How to select distinct based on multiple values for one column
I feel this is a very easy task and I am grossly overthinking it. I have looked and looked nothing seems to answer my question. My question is simple, how do I select distinct on one column, based on …
Can we use arithmetic operators (+, -. *, or /) on date functions in mysql?
I am learning mysql and I am stuck in the following question. Can we use arithmetic operators (+, -. *, or /) on date functions in mysql? Can someone help me out with it?