• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting all tables and columns that have a foreign key references to the given table's key

 
sandeeprajsingh tandon
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I wrote a query for getting all tables and columns that have a foreign key references to the given table's key. Can you help me write it efficiently. Basically i want to avoid the outermost select statement which is written only to get the "referenced column name"..is there a way to get the referenced column name in the 2nd select statement thereby avoiding the outermost.

 
Dave Tolls
Ranch Hand
Posts: 2369
25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first thought is, how do you know it'll make it more efficient? You might need to define "efficient" to answer that one.

My second is, unless you want the column_name to be part of the distinct, then you can't.
If it can be part of the distinct then you can simply put those joins and filters into the inner query.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!