In a SQL Server statement there is SELECT id, book, acnt, prod, category from Table1 UNION SELECT id, book, acnt, prod, category from Table2 The first …
Tag: union
Merge two tables and chain id fields in order
I’m looking for a way to merge two tables (or more) and modify/order their numeric id. To put it simply here is what I want to do schematically : Table example 1 : Id Field 4 x 1 x 5 x 3 x 2 x Table example 2 : Id Field 1 x 3 x 5 x 2 x 4
SQL Query — AVG for Occurrence Across Multiple Columns
I have a table like the following ID_A ID_B Avg_Class_Size 1 2 16 3 4 10 2 3 8 2 4 9 Where ID_A and ID_B represent distinct student ID codes, and AVG_Class_Size represents the average class size of the classes shared between students A and B. I would like to calculate the average of the “avg_class_size&…
sql – union tables with same prefix
I have a set of tables with same prefix and same structure. All I need is to “combine” them as one. Basically I retrieve tables with certain pattern from information_schema.tables, then get rid of the last union all. Above method works for 20-30 tables, as the @result won’t exceed the limit …
Consolidate SQL Union With JOIN
Let’s say I have 2 tables (bar_helper and bar). I have a query that retrieves records based on a JOIN between the tables and some condition. Essentially, my first result set is joined and I want my second one to be unconditional and just based on one table. This works fine. However, now I need to also g…
Unpivot Data Using MS Access Query
Hoping someone with Access & SQL experience would be able to write some SQL code that I could use in MS Access to transform/unpivot some data. I’ve spent a day trying advise from others who have asked similar questions here, but I have no SQL experience and have failed miserably so far. Answer You c…
Access: Issue Creating SQL View Through VBA – Unions not allowed in subquery
First of all, let me preface this with something I almost always say in my few posts so far, which is that I’m not an IT/tech person. I’m an accountant who likes to dabble a little bit in SQL and so …
SQL – Snowflake Minus Operator
Hi I am running a query to check for any changes in a table between two dates…. The first select statement (where run_time = current_date() return 3,357,210 records. The second select statement (where run_time = current_date()-1 returns 0 records. Using the MINUS operator, I was expecting to see 3,357,2…
Return in which or statement results are from SQL [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 1 year ago. Improve this question I’m having the following SQL statement, to return worksheets that teachers have liked, …
What is the type casting hierarchy in mysql?
Taking the following example: If I only include the first select statement in the cte, the type will be int. If I include the first and second, the type will be DECIMAL, and if I include all three, the type will be cast to VARCHAR (regardless of position of the three statements). How does mysql determine whic…