Does Excel as something similar to SQL "Except"? - sql

I am able to perform Union of two tables in MS Query of excel but its throwing error for "Except".
Can someone please let me know is there anyway to use "Except" of two tables in Excel.
SELECT * FROM [Book1query] tbl2
EXCEPT
SELECT * FROM [Merge1] tbl1

EXCEPT returns only rows, which are not available in the second SELECT statement. In other words, a join type of left anti.
In Power Query you can do that with a Merge of two tables, using the Join Kind option for Left Anti.
For a detailed description of all the Join Kind options, visit https://radacad.com/choose-the-right-merge-join-type-in-power-bi

Related

Best way to "SELECT *" from multiple tabs in sql without duplicate?

I am trying to retrieve every data stored in 2 tabs from my database through a SELECT statement.
The problem is there are a lot of columns in each tab and manually selecting each column would be a pain in the ass.
So naturally I thought about using a join :
select * from equipment
join data
on equipment.id = data.equipmentId
The problem is I am getting the equipment ID 2 times in the result.
I thought that maybe some specific join could help me filter out the duplicate key, but I can't manage to find a way...
Is there any way to filter out the foreign key or is there a better way to do the whole thing (I would rather not have to post process the data to manually remove those duplicate columns)?
You can use USING clause.
"The USING clause specifies which columns to test for equality when
two tables are joined. It can be used instead of an ON clause in the
JOIN operations that have an explicit join clause."
select *
from test
join test2 using(id)
Here is a demo
You can also use NATURAL JOIN
select *
from test
natural join test2;

SQL INNER JOIN duplicate columns

I am trying to return some columns from 2 tables which share an ID column using the following browser database query system, which reads from the tables shown on this webpage. I believe the way to do this is by using INNER JOIN (e.g. see this guide).
SELECT sami_dr2.DR2Sample.CATID,
sami_dr2.DR2Sample.Mstar,
sami_dr2.StellarKinematics.PA_STELKIN
FROM sami_dr2.DR2Sample INNER JOIN sami_dr2.StellarKinematics
ON sami_dr2.DR2Sample.CATID = sami_dr2.StellarKinematics.CATID;
However, when I run this query I get the error message:
sql: Duplicate columns are not supported. Try using an alias for those columns within the SELECT clause e.g., SELECT t1.CATAID, t2.CATAID becomes SELECT t1.CATAID as t1_CATAID, t2.CATAID as t2_CATAID
But as far as I'm aware the whole point of using the INNER JOIN is to remove duplications as I'm not returning sami_dr2.StellarKinematics.CATID in my output table, only sami_dr2.DR2Sample.CATID.
I've also found that using SELECT sami_dr2.DR2Sample.CATID as ID_1, sami_dr2.StellarKinematics.CATID as ID_2 in the selction doesn't fix the problem either.
Any help on this would be greatly appreciated!

Select query for Multiple tables with one Common Column

a select query for Multiple tables with one Common Column
i have tried something below but not working
Select * from DM_Audit da, DM_APPLICANTS dap , DM_POLICY dp, DM_Names dn,DM_Address ad
where da.fk_applicationID=dap.fk_applicationID and
dap.fk_applicationID=dp.fk_applicationID and
dp.fk_applicationID=dn.fk_applicationID and
dn.fk_applicationID=ad.fk_applicationID
Here fk_applicationID is Common column in all the table
New to the Sql Please Help
The column name may be the same, but does it reference data for the intended records in each table?
If it definitely does, then re-writing the query using joins would be an easier way of checking the links:
Select *
from DM_Audit da
INNER JOIN DM_APPLICANTS dap ON dap.fk_applicationID=da.fk_applicationID
etc........
I would usually have a 'key' table in this situation (i.e. with the most data in it, or one which links to the most other tables which need to be joined) Then it is much easier to join the other tables.
N.B. if not all tables join to the key table, join as many as you can first, then join to the 'joined' tables further down the statement.

Need help forming SQLite join query

I've been able to make a query using MS Access 2010 that does just what I want but I am having trouble doing so in SQLite3. Here is the Access SQL
SELECT pubacc_lo.*
FROM pubacc_en
LEFT JOIN pubacc_lo ON pubacc_en.call_sign = pubacc_lo.call_sign;
Basically it selects all of the columns in the pubacc_lo table and the rows where the call_sign fields are equal between the tables. This does not select any of the pubacc_en data into the final query in MS Access.
Playing around in SQLite 3, the closest I've gotten was
SELECT * FROM PUBACC_LO, PUBACC_EN WHERE PUBACC_en.call_sign=PUBACC_LO.call_sign
But this statement selects all of the data in the EN table along with the LO table (cross join?). I've tried some left outer joins but haven't had any luck. Any tips would be appreciated!
You should be able to use the same query as you got from Access. SQLite3 does support left outer joins.
As for your query, if you only want the fields from the LO table, then ask for that in your SELECT clause like this:
SELECT PUBACC_LO.*
FROM PUBACC_LO, PUBACC_EN
WHERE PUBACC_en.call_sign=PUBACC_LO.call_sign
but the problem here is that it will only return call_signs with entries in both tables, while the outer join from access will return all rows from PUBACC_EN irrespective of whether there is a corresponding PUBACC_LO entry..
SELECT pubacc_lo.* FROM PUBACC_LO, PUBACC_EN WHERE UBACC_en.call_sign=PUBACC_LO.call_sign
If you only want to select pubbac_lo's field, this is what you can use.

methods of joining 2 tables without using JOIN or SELECT more than one distinct table in the query

Is there a way of joining results from 2 tables without using JOIN or SELECT from more than one table? The reason being the database im working with requires queries that only contain SELECT, FROM, and WHERE clauses containing only one distinct table. I do, however, need information from other tables for the project i'm working on.
More info: the querier returns the query results in a .csv format, is there something we can manipulate there?
Pick a programming language. Any language will do. Run one query, and get the results. Run another query, get the results. Use the programming language to combine the results.
Seriously. You are asking how to join data from a database that doesn't support joins. If the database doesn't support it, you're going to have to do it externally.
select a.*, b.* from tablea a, tableb b
You can do it either by Using JOIN or SELECT. You have to use one of it. By Join you must be knowing. I am writing an example for without using JOIN and just using SELECT, to join two tables.
SELECT * from Table1, Table2 where Table1.common_attribute = Table2.common_attribute;