I am trying to re build Microsoft Access queries in Datameer v6. I am fairly new to Datameer so I do not have that much experience.
I am trying to determine the order of which Datameer executes its joins, like for example is it enough to just keep adding joins within the same sheet or do I have to join 2 sheets, then use the joined sheet as the final product for the next join.
Here is my Access join statement
Team_Template_ID INNER JOIN (dbo.Cabinet LEFT JOIN
(((((((((dbo.Procedure RIGHT JOIN dbo.Folder ON dbo.Procedure.FolderID = dbo.Folder.ID)
LEFT JOIN Example ON dbo.Procedure.Step = Example.CategoryID)
LEFT JOIN Example AS Example_1 ON dbo.Procedure.CategoryCID = Example_1.CategoryID)
LEFT JOIN Example AS Example_2 ON dbo.Procedure.VisitCID = Example_2.CategoryID)
LEFT JOIN Example AS Example_3 ON dbo.Procedure.LocationCID = Example_3.CategoryID)
LEFT JOIN Example AS Example_4 ON dbo.Procedure.FrequencyCID = Example_4.CategoryID)
LEFT JOIN Example AS Example_5 ON dbo.Procedure.UserType1CID = Example_5.CategoryID)
LEFT JOIN Example AS Example_6 ON dbo.Procedure.UserType2CID = Example_6.CategoryID)
LEFT JOIN Example AS Example_7 ON dbo.Procedure.IndustryCID = Example_7.CategoryID) ON dbo.Cabinet.ID = dbo.Folder.CabinetID) ON Team_ID.Team_ID = dbo.Cabinet.ID
Do I do a "Simple" join on datameer then click the "+" button to add additional joins and follow my Microsoft access join sequence?
Cheers
According your description and the documentation about Joining Data in Datameer v6, you can do a Simple join and Add additional joins to follow your sequence.
The first plus sign lets you make join operation on the same table with different columns, and the second one lets you join a table with other tables.
Related
I'm populating a table which is fetching the ids from 2 other tables to display their information, for example, delivery has a Hamburguer and the box, but the user might register the delivery with out the box, only with the hamburguer.
When I make a INNER JOIN SELECT to get the data from the DB it will return 0 results since there is no box and I'm trying to compare the ids that don't exist. It doesn't populate the table then.
SELECT
entrega_telemovel.*,
telemovel.id_telemovel,
telemovel.nroserie,
nro_telemovel.numero_telemovel,
nro_telemovel.id_nrotelemovel,
funcionarios.id_funcionario,
funcionarios.nome
FROM entrega_telemovel
INNER JOIN telemovel
ON entrega_telemovel.telemovel = telemovel.id_telemovel
INNER JOIN nro_telemovel
ON nro_telemovel.id_nrotelemovel = entrega_telemovel.numero_telemovel
INNER JOIN funcionarios
ON funcionarios.id_funcionario = entrega_telemovel.funcionario_entrega
ORDER BY funcionarios.nome;
In this query above entrega_telemovel.telemovel=telemovel.id_telemovel the value in entrega_telemovel.telemovel is null like the example I gave above. So 0 results are returned from the query.
How can I solve this ?
You are looking for a LEFT JOIN.
INNER JOIN only combines rows, that exist in both tables. A LEFT JOIN on the other hand always produces at least one row. If on table does not have a match for it, all columns are set to NULL.
SELECT
entrega_telemovel.*,
telemovel.id_telemovel,
telemovel.nroserie,
nro_telemovel.numero_telemovel,
nro_telemovel.id_nrotelemovel,
funcionarios.id_funcionario,
funcionarios.nome
FROM entrega_telemovel
LEFT JOIN telemovel
ON entrega_telemovel.telemovel = telemovel.id_telemovel
LEFT JOIN nro_telemovel
ON nro_telemovel.id_nrotelemovel = entrega_telemovel.numero_telemovel
LEFT JOIN funcionarios
ON funcionarios.id_funcionario = entrega_telemovel.funcionario_entrega
ORDER BY funcionarios.nome;
You want to show all entrega_telemovel entries, no matter whether they have a match in entrega_telemovel or not. This is what an outer join does.
SELECT ...
FROM entrega_telemovel et
LEFT OUTER JOIN telemovel t ON et.telemovel = t.id_telemovel
...
I'm trying to run a multi delete on a my database but when it runs it runs with no errors but nothing was deleted? is it a case that an inner join will fail if even one of the table doesn't have anything to link to another and on?
using the query in an Express.js api I'm trying to finish us.
I usual test big queries like this in DBMS before i place them in my api.
below is the query:
DELETE task,issue,milestone,help_source,project_task,project_source,project_milestone,task_created_by,mileStone_created_by,issue_created_by,source_created_by,task_issue,milestone_task,project_creation,project
from project_creation
INNER JOIN project_milestone ON project_milestone.projectId = project_creation.projectId
INNER JOIN project_task ON project_task.projectId = project_creation.projectId
INNER JOIN project_source ON project_source.projectId = project_creation.projectId
INNER JOIN task_created_by ON task_created_by.taskId = project_task.taskId
INNER JOIN mileStone_created_by On mileStone_created_by.mileStoneId = project_milestone.mileStoneId
INNER JOIN source_created_by ON source_created_by.sourceId = project_source.sourceId
INNER JOIN task_issue ON task_issue.taskId = project_task.taskId
INNER JOIN issue_created_by ON issue_created_by.issueId = task_issue.issueId
INNER JOIN milestone_task On milestone_task.taskId = project_task.taskId
INNER JOIN task On task.taskId = project_task.taskId
INNER JOIN issue ON issue.issueId = task_issue.issueId
INNER JOIN milestone ON milestone.mileStoneId = project_milestone.mileStoneId
INNER JOIN help_source On help_source.sourceId = project_source.sourceId
INNER JOIN project ON project.projectId = project_creation.projectId
WHERE project.projectId = 59;
is there some error in my logic? and if yes what is it? or is it deleting without me knowing?
Questions you may ask:
Did i try searching stack overflow?
ANS: yes i did but can't seem to find an answer that fits this weird situation
so there is no error?
ANS: no there is no errors when i run the query
try to look on that topic :
How to Delete using INNER JOIN with SQL Server?
As far as I could see you need to specify aliases for each table.
So task, issue... are aliases but cannot see any of then after inner-join table name
(true, same names as tables but maybe alias are required)
Eg: INNER JOIN task task ON...
(now task is an alias, so you delete from table task)
Didn't check it, but if is to be work that should be the fix.
This is my structure of tables:
tables_structure
and there's tbl_owner, tbl_rooms and tbl_class.
How do I get id_class and class name from tbl_class.
The original source code is like this:
SELECT
clas.id_class,
clas.class_name
FROM
tbl_rooms AS room
LEFT JOIN tbl_class AS clas ON room.id_class = clas.id_class
LEFT JOIN tbl_owner AS own ON room.id_owner = own.id_owner
WHERE own.id_owner='1';
However, it did not work. Please help me?
SELECT
clas.id_class,
clas.class_name
FROM
tbl_rooms AS room
LEFT JOIN tbl_class AS clas ON room.id_class = clas.id_class
LEFT JOIN tbl_owner AS own ON room.id_owner = own.id_owner
WHERE own.id_owner='1';
Left Joins and wheres can be a little confusing.
Here you are asking for all rooms and if they have a class return it, it they have an owner return it. Which is done by the left join.
Then after getting that info, Your asking to filter the results by owner = 1
Given that there were left joins used to build this data, you have now said only show the results where both joins matched. Effectively turning the left join to an inner join.
I would take away the where clause and check the join conditions are producing results you expect first, then start to allow the where to narrow the result set.
The correct way to check if a left join is a condition is (own.id_owner='1') OR (own.id_owner is null)
That will bring back all owner = 1 and all unknown owners
Information
Is there a way that I can retrieve two bits of information from another(same) table twice in one LEFT JOIN?
Attempt
Below is the SQL query I tried to put together in hopes would work. I hope you can see what I am trying to do from it.
SELECT cards.*, list.name FROM cards
LEFT JOIN list ON cards.main = list.id AS main_name
AND cards.enemy = list.id AS enemy_name
WHERE cards.id = 1
As you can see above I am trying to retrieve the names of two values cards.main AND cards.enemy from the list table.
Thank you, and any questions will be answered asap!
You have to join the list-table twice:
SELECT cards.*, main_name.name, enemy_name.name
FROM cards
LEFT JOIN list AS main_name ON cards.main = main_name.id
LEFT JOIN list AS enemy_name ON cards.enemy = enemy_name.id
WHERE cards.id = 1
SELECT a.acikkapali,
b.onay, b.evrakno,
b.tarih,
a.kod,
d.ad,
a.note0,
a.sf_miktar,
a.sf_sf_unit,
a.rtalepedilentestarih,
c.evrakno
FROM stok47T a
LEFT JOIN stok47e b on a.evrakno = b.evrakno
LEFT JOIN stok46t1 c on a.evrakno = c.talepno
LEFT JOIN stok00 d on a.kod = d.kod
WHERE a.tarih = '2013/04/15'
I need to add two my tables into that script with right way that means If I mapped one of them then the normal row count increases this makes me crazy, I have been trying to solve that issue for a couple days but I had been fail many times.
I couldn't find a good mapped fields between stok47t and the others. But there are still a few columns(fields) matches for their types and data.
I need to listen ppl opinions and learns something.
Here is a big part of my query
If you are getting increase in row count then chances are it could be due to using LEFT JOIN. An INNER join might help (see http://www.codinghorror.com/blog/2007/10/a-visual-explanation-of-sql-joins.html guidance)
SELECT a.acikkapali,
b.onay, b.evrakno,
b.tarih,
a.kod,
d.ad,
a.note0,
a.sf_miktar,
a.sf_sf_unit,
a.rtalepedilentestarih,
c.evrakno
FROM stok47T a
INNER JOIN stok47e b on a.evrakno = b.evrakno
INNER JOIN stok46t1 c on a.evrakno = c.talepno
INNER JOIN stok00 d on a.kod = d.kod
WHERE a.tarih = '2013/04/15'
However without understanding your data structure then there is a chance you might lose the information that you are after.
If you are getting multiple rows, it is probably due to a Cartesian product occurring in the joins. This is unrelated to the type of join (left/right/full/inner). It is based on the relationships between the tables. You have 1-N relationships along different dimensions.
Your conditions are:
FROM stok47T a
LEFT JOIN stok47e b on a.evrakno = b.evrakno
LEFT JOIN stok46t1 c on a.evrakno = c.talepno
LEFT JOIN stok00 d on a.kod = d.kod
I have no idea what these tables and fields mean. But, if you have a case where there is one row per evrakno in table stok47t, and there are two rows in table stok47e and three in table stok46t1, then you will get six rows in the output.
Without more information, it is impossible to tell you the best solution. One method is to summarize the tables. Another is to take the first or last corresponding row, by doing something like:
from stok47T a left join
(select s.*, row_number() over (partition by evrakno order by id desc) as seqnum
from stok47e s
) b
on a.evrakno = b.evrakno and b.seqnum = 1