Skip to content

CTE Recursive Query to Grandparents

I have following table: What I need to get is SELECT query that will return only rows that have ISDELETED 0 and ISINEDIT 0 and whose parents or grandparents are 0 as well I currently have: But for some reason it returns double rows Answer You need to add the same isdeleted = 0 AND isinedit = 0 predicate to

SQL Data range using Case

I have table1 with data Age 10 21 35 50 and my query select count(*) as Total, * from ( select case when age <18 then '0-20' when age between 20 and 29 then '20-29' when age between 30 …

Count json tags in sql

I have this json strings And know i want the following output I wanted to do this with a sql query. If you know how to do this, thanks in advance! Answer If you’re not using MySQL 8, this is a bit more complicated. First you have to find a path to a name element that has the value phone

SQL, Determine if Records in Table A exist in Table B

TableA has columns AccountNum and RoutingNum TableB also has columns AccountNum and RoutingNum Table B is more trustworthy. So, I would like to find if all records in Table A exist in Table B. And if not, which records do not match. Is this on the right track? Your solution would be greatly appreciated. Answe…

SQL Insert with Inner Join trying to insert into wrong column

I have an existing table of products, and I’m trying to insert new attributes from other tables into my main product table. Here’s my query: The error that I get is: Field ‘product_id’ doesn’t have a default value. I’m not trying to insert into the product_id column, I&#821…