sql server - Join TSQL Tables in same DB -


i want simple join of 2 tables in same db.

the expected result is: node_id's table t_tree same tree_category table t_documents

my t_documents tabel:

+--------+----------------+---------------------+ | doc_id | treee_category |        desc         | +--------+----------------+---------------------+ |  89893 |           1363 | test                | |  89894 |          1364  | tab or 4 spa | +--------+----------------+---------------------+ 

t_tree tabel

+----------+-------+ | node_id  | name  | +----------+-------+ |    89893 | hallo | |   89894  |   bb  | +----------+-------+ 

doc_id primary key in t_documents table , tree_category foreign key

node_id primary key in t_tree tabel

select dbname.dbo.t_tree.node_id dbname.dbo.t_documents  inner join tree_category on t_documents.tree_category = dbname.dbo.t_tree.node_id 

i can not figure out how correctly .. right approach ?

you close. try this:

select t2.node_id dbname.dbo.t_documents t1 inner join dbname.dbo.t_tree t2     on t1.doc_id = t2.node_id 

comments:

  • i used aliases in query, sort of shorthand table names. aliases can make query easier read because removes need list full table names.
  • you need specify table names in join clause, , columns used joining in on clause.

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -