I'm trying to create a view based on three tables: a master table and two child tables. The two child tables are...
independent, but they are related to the master table through a foreign key, When I query the view, Oracle gives the results repeating for each table the number of records from the other table.
An example would have been nice to better diagnose the problem....
Your problem doesn't have to do with the view, but the underlying query of the view. In particular, make sure that you pay attention to your WHERE clause, which specifies how the join is to take place. Since you are joining three tables, you need to specify two join conditions in the WHERE clause.
For instance, suppose I have three tables, A,B, and C. To further match your example, assume that table A is the "master" table and tables B and C are the "child" tables. My WHERE clause might look something like the following:
WHERE A.b_id = B.id AND A.c_id = C.id AND (add other limiting conditions here)Make sure that your WHERE clause is correct.
For More Information
- Dozens more answers to tough Oracle questions from Brian Peasland are available.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
Dig Deeper on Oracle database design and architecture
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.