Query to invoke a function - Access 2003 vba - ms-access

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
)

Related

sql injection with union

So I am doing a little sql injection challenge because I wanted to learn about it and I have a question. I type 'hi' into the HTML form and I get this back as a response
Error: The following error occurred: [near "hi": syntax error]
Query: SELECT * FROM personnel WHERE name=''hi''
The information we need to get is located in a table called users. I was looking at sql and I see here the union operator which combines the results of 2+ select statements.
So, I try this as input: 1 UNION SELECT * FROM users and I get nothing back so it looks like it searched from that input as a name in table personnel. I thought this would work because the query would look like: SELECT * FROM personnel WHERE name=1 UNION SELECT * FROM users. Am I not understanding how the union operator works or is something else wrong in my input
This one:
set #hi = "'hi'";
select #hi;
SELECT * FROM personnel WHERE name="'hi'"
Simulate:
insert into personnel (`name`) values("'hi'");
insert into personnel (`name`) values("'hello'");
select * from personnel where `name` != "'hi'"
-- you can't use a double '' in sql query
Query: SELECT * FROM personnel WHERE name='hi'
Probably the SQL is invalid because personnel and users have different shape. You need to inject something that is identical to the initial select.
Also your entire problem goes away if you have parameterised queries instead of concatenating into SQL.

WSO2 DAS: SPARK SQL query with UNION producing errors

The following query was attempted to be executed when performing batch analytics with WSO2 DAS using Spark SQL. Tables 'First', 'Middle' and 'Third' are required to be combined and written to table 'All_three'.
INSERT OVERWRITE TABLE All_three
SELECT SYMBOL, VOLUME FROM First
UNION
SELECT SYMBOL, VOLUME FROM Middle
UNION
SELECT SYMBOL, VOLUME FROM Third;
Following error is displayed on WSO2 DAS when this query is executed:
ERROR: [1.79] failure: ``limit'' expected but `union' found INSERT OVERWRITE TABLE X1234_All_three SELECT SYMBOL, VOLUME FROM X1234_First UNION SELECT SYMBOL, VOLUME FROM X1234_Middle UNION SELECT SYMBOL, VOLUME FROM X1234_Third ^
Using LIMIT with UNION is not a necessity to the best of my knowledge. Enclosing the SELECT queries in parentheses too was attempted which didn't work. What am I doing wrong here? Thank you in advance!
I had the same issue.
Please make sure you had an whitespace in end of each row.
The reason is it is not considering \n as a whitespace like SSMS or other query editors.
So it reads your query without whitespace.
Hence, it read like SELECT * FROM FirstUNION not like SELECT * FROM First UNION
My issue was resolved and I hope this helps for you too.
There exists a problem with the query you mentioned here. Please change the query as below.
INSERT OVERWRITE TABLE All_three
select * from (
SELECT SYMBOL, VOLUME FROM First
UNION
SELECT SYMBOL, VOLUME FROM Middle
UNION
SELECT SYMBOL, VOLUME FROM Third
) temp;
Actually what we do here is, wrapping the union result into temporary data element called temp and select everything from there. Spark-SQL parser only takes single select element in the insert queries, and at the end of a select query it expects a limit (if available). therefore, you need to wrap the subsequent select statements into one select element. Hope this resolves your issue.

Grouping two mySQL select statements under one alias and ordering that alias

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

Mysql Query from Two table

Is it possible to join Two queries of mysql in a query ??
Like:
select * from a + select * from b
So that I can use them in a single php loop.
If they have the same number of columns and the datatypes are the same in each column, then you can use a UNION or UNION ALL:
select *
from a
UNION ALL
select *
from b
If you provide more details about the tables, data, etc, then there might be another way of returning this data.
A UNION will return only the DISTINCT values, while a UNION ALL selects all values.
If this is the route that you need to take, and you still need to identify which table the data came from, then you can always create a column to identify which table the data is from , similar to this:
select *, 'a' TableName
from a
UNION ALL
select *, 'b' TableName
from b
This allows you to distinguish what table the data came from.
I think it is easier creating sql "variables" like:
select varA, varb from TableA, tableB;
and you can just play with values in PHP accessing properties.
That way you can take conditions in the query like:
select varA, varb from TableA, tableB where varA.id = varB.foreingId bla bla...
;)

MYSQl Query with union is failing

I have a two tables A and B
I would like to union them and store in to another table;
CREATE TABLE myspace.test (
(select * from A ) UNION ( select * from B) );
It fails with an error
You have an error in your SQL syntax;
check the manual that corresponds to
your MySQL server version for the
right syntax to use near 'CREATE TABLE
myspace.test ( (select * from A )
UNION ( s' at line 1
But the query with: (select * from A ) UNION ( select * from B) gives correct result.
How to store union result in to another table??
Thanks Arman.
EDIT
Well After playing around I found that:
The query without outer brackets works.
CREATE TABLE myspace.test
(select * from A ) UNION ( select * from B) ;
Adding AS is not solving the problem.
I was wondered that query with brackets is working well seems tome BUG or maybe I am missing something?
CREATE TABLE myspace.test
(select * from A);
CREATE TABLE
myspace.test
AS
SELECT *
FROM A
UNION
SELECT *
FROM B
Read the documentation. There are no parens around the select-statement.
CREATE TABLE `myspace`.`test` (SELECT * FROM `A`) UNION (SELECT * FROM `B`);
Watch out for duplicate primary keys, though. You may want to consider first creating an empty table myspace.test with the proper layout, then inserting rows into it more selectively.
This does not look right at first sight.
Start by simply creating your new empty table using CREATE TABLE.
Then run a query to populate it, should be something like
INSERT INTO newTable(field1, field2,..., fieldN)
SELECT temp.field1, temp.field2,...,temp.fieldN
FROM
(
SELECT field1, field2,...,fieldN
FROM A
UNION
SELECT field1, field2,...,fieldN
FROM B
) temp
Hope this helps!