I have 2 databases. In database1, I want to run a query from database2 and UNION ALL the results. This is the syntax I tried, but I get an error of
Syntax error in from clause
Here is the syntax I tried --- where is my error?
SELECT * FROM query1
UNION ALL
SELECT * FROM query1 IN C:\Database\production.mdb
Add quotes around the path of the external database.
I would also use aliases to distinguish between the 2 instances of query1.
SELECT q1Local.* FROM query1 AS q1Local
UNION ALL
SELECT q1Remote.* FROM query1 AS q1Remote IN 'C:\Database\production.mdb'
Related
I'm trying to retrieve all tables with specific name format,
for performing union among those tables.
I'm using mysql Ver 8.0.13, and i wrote this following query for retrieving the relevant tables:
show tables LIKE REGEX '^table_.+_class$';
I couldn't figure out the correct syntax for this query :/
Afterwards i'm planning to union all those tables.
I would like to avoid writing this code since it doesn't scale nicely:
SELECT * FROM table_french_class
UNION
SELECT * FROM table_history_class
UNION
SELECT * FROM table_pingpong_class
UNION
SELECT * FROM table_math_class
UNION
SELECT * FROM table_literature_class
Can someone suggest me how to handle this issue?
Thank you
You could use INFORMATION_SCHEMA catalog:
SELECT *
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME REGEXP '^table_.+_class$';
Mysql SQL Quires and Output
Query 1:
Query 2:
Union of above two queries:
Expected output:
The main problem is in the call of the sql function in the query, Try with this:
SELECT 'MEAN','STANDARD_DEVATION','MAX','MIN','VARIANCE'
UNION
SELECT * FROM ( SELECT AVG('MetricValue'),STDDEV_SAMP('MetricValue'),MAX('MetricValue'),
MIN('MetricValue'),VAR_SAMP('MetricValue')
FROM 'XR_METRIC_ANALYSIS' ) as temp
This is a possible solution
I want to run two mysql SELECT statements, combine them, call the new combination by its own name, then order that new combination by a user-defined function. This is what I am trying currently:
SELECT * FROM (
SELECT * FROM dictionary WHERE def1 LIKE '$input%'
UNION ALL
SELECT * FROM dictionary WHERE def2 LIKE '$input%'
) AS newcol
ORDER BY levenshtein('$input', newcol)
LIMIT 10
But I get the following error:
Unable to run query:Unknown column 'newcol' in 'order clause'
The problem is clearly with defining the new group 'newcol'.
You're trying to order by a TABLE, not by a FIELD! Use a field from your tables ant it'll go smooth
I have multiple tables named as: data_yyyymmdd.
Ex. data_20121028, data_20121029, ...
Each table have same fields. How can I get all the records from all those tables?
SELECT * FROM data_20121028
UNION
SELECT * FROM data_20121029
UNION
...
MySQL 5.6 Reference Manual: UNION Syntax
I have a function in a module (the function combines 6 tables into a new one, then looks up another table to update one of the field values in the new table) and all is working perfectly well. Now I would like to call this function from an access 2003 query so that when i run the query the New Table should be opened.
I tried using Expr: in the query but although the new table is being created in the 'Tables' Section (by invoking my function), all I can see when i run the query is a blank table with one column named 'Expr'.
Can anyone please guide me to the right direction?
Any help would be greatly appreciated.
You can use in your select ..
SELECT * INTO TBL_ALLTABLES
FROM (
--Here your select union all tables for example
SELECT * from tbl1
UNION ALL
SELECT * from tbl2
UNION ALL
SELECT * from tbl3
UNION ALL
SELECT * from tbl5
UNION ALL
)