Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

sql querry w/ relationship many to many

 
chrstian ferma
Ranch Hand
Posts: 72
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plants
id
name

animals
id
name

plants_animals
palnts_id
animals_id

help, im having a problem in my querry is it possible that in table plants i can retrieve all the animals? same in table animlas can retrieve all the plants?

select
a.id as "a_id",
a.name as "a_name"
from plants_animals pa
inner join animals a on
pa.plants_id = a.id
where pa.plants_id = #{id}

this is my querry im thanks my goal is to retrieve the list of animals in plants

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible. What problems are you experiencing?

This looks fishy:
chrstian ferma wrote:
inner join animals a on
pa.plants_id = a.id

Shouldn't it be pa.animals_id = a.id?
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!