Skip to content

Tag: mysql

Search data based on two columns SQL

I have a database table like this: I need search from Id the Id’s that not have Tipo = Inventario and Create a new line with that data, I mean for example, RTOR-00261 and RTOR-0255 dont have INVENTARIO, I need to create new with the fields that there is in SUSTRATO. All data are in the same table Final …

Comparing count(*) with select for one result

I have a table tb_xyz having field1, field2 as indexed. Now I have two queries: and Assuming both queries are written to just check if this condition is met at least once. Which of them is more optimal. I tried checking for their execution times, but results were mixed, for small data. Answer The first query …

Query based on some data multiple compare

Table: How do i bring the period when customers have max cc_limit? If the cc_limits same for customer for more than one month, take the period with highest year-month data Answer Use row_number() window function,Below should work. EDIT : To clarify why order by should be in the inline view. Scenario : When th…