Skip to content

Tag: sql

Find the names of last queried tables

I have a query inside my PHP program like I want to know the names of the tables called in this query, including joined tables. The aim is to find the schema of the affected tables which is required for further operations. Is there a direct query to do this or will I have to use some Regex? Answer You

How to join two unrelated table in MySQL?

I have two unrelated tables and I need to join in a single row as expected output below. I tried below query and doesn’t work. How to make join these tables?? Table 1 | col1 | amount| | a | 200 | …

SQL loop through columns with name to find max date

I’m looking for the SQL to loop through 20 columns with dates, to find the max. My code is kind of bad now: it’s oracle database, i konow that max date is in filed annex_20 Answer First of all, you don’t need ANNEX_XX_DATE is not null since ANNEX_XX_DATE<>… can’t be true if…

How to unnest multilevel structs in BigQuery?

I have many tables with different table suffixes in BigQuery where each table has four level structs in each row. I made query to unnest it into flattening table. It works correct but not very well because it is seems like too long. How can I make it simpler and more effective? Any suggestions. Thank you. Ans…

SQL Query Performance Enhancement on NOT IN

Suppose I have a query need to lookup users who bought book A but not bought book B. Typical SQL query can be: This not in query looks not efficient, any enhancement I can do this query? Answer Try using exists clause instead of IN clause – Apart from this you my try having index on below columns &#8211…