I need to retrieve fields from a relational database that has more than twenty tables. I am having difficulty in extracting required 63 fields from the database. Someone advice please.
but then this one will give you a cartesian product if you don't have what you are checking against.
To avoid it you need to select where e.g. two or more columns have a relationship you can check against. Let's say if in tableOne the column tb1Col1 is the primary key column of that table and tb2Col2 is the foreign key column in tableTwo linked to tableOne and tableThree is linked to tableOne via foreign key in column tb3Col2 then your SQL query would be as follows;
(I'm pointing to Oracle as I saw the SQL*Plus tag)
As for the material on the SELECT, see http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_10002.htm .
Usually the relationships mentioned by Joseph above are reflected in the fact that two tables show the same column names, in that case, the NATURAL JOIN clause of the SELECT statement can shorten and cleanse the syntax.
Also, if that query is really complex and you need its results in a sort of "table" of its own, consider creating a view. Refer to the documentation http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_8004.htm
You should certainly use the chapter on joins. MySQL documentation contains a long description of all types of joins including examples. You should do the examples on your sample database, the differences between all kinds of joins are not visible just from looking into the manual, you have to try yourself. To make it clear, a.tb1Col1 = c.tb3Col2 is not a NATURAL JOIN, it is LEFT JOIN ON a.tb1Col1 = c.tb3Col2. Keys are not needed for joins. However, PRIMARY KEY or UNIQUE will ensure that you have at most one row with such a vallue. If the tables are indexed using all columns that you need for search and relations, your queries will be much faster. Foreign keys do not server primarily for queries, they help because they must be UNIQUE but their role is to help you to maintain database integrity.
We can best help if you'll output the DDL schema (script it) and define the query requirements needed. There's much to consider, especially if the database isn't normalized or lacks data-integrity.
first thing we should know , How your trying to retrieve ? in a single query u have more than 20 tables. ?
if this is the case use joins, and sub queries.
retrieving data from database is based on the table structure and the way we normalize the tables. so please check the tables and the relation ships between those.
we can also use views. for faster retrieving and we can also use indexes.