<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4331432086635454742</id><updated>2012-02-16T06:41:06.547-08:00</updated><category term='inheritance'/><category term='Word Frequency'/><category term='JPA'/><category term='outer join inner tables create left outer join right ORM hibernate'/><category term='MySQL'/><category term='total number of words'/><category term='word count'/><category term='java'/><category term='Rajeev Kuruganti'/><category term='Rajeev'/><category term='English'/><category term='students'/><category term='secondaryTable 4circles secondary table blog'/><category term='4 Circles LLC'/><category term='4 Circles'/><category term='Hibernate'/><category term='Object Oriented Databases'/><category term='word'/><category term='Databases'/><category term='j2ee'/><category term='Non Relational Databases'/><category term='Oracle'/><category term='writers'/><category term='frequency'/><title type='text'>4 Circles Blog</title><subtitle type='html'>Word Frequency, applications, java, j2ee web services, Hibernate, programming, design, Spring, Oracle, Small Medium Business web sites, learning fundamentals,</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://4circlesllc.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://4circlesllc.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Rajeev</name><uri>http://www.blogger.com/profile/01677662936254968409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4331432086635454742.post-6053115379767380365</id><published>2011-03-29T14:19:00.000-07:00</published><updated>2011-03-29T14:19:46.792-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='outer join inner tables create left outer join right ORM hibernate'/><title type='text'>Databases - Basics</title><content type='html'>In the previous post - &lt;a href="http://4circlesllc.blogspot.com/2011/01/databases-introduction.html"&gt;Databases Introduction&lt;/a&gt;&amp;nbsp; we glimpsed at&amp;nbsp;different types of databases and simple concepts of tables. In this section we will look at some basics of databases- tables, inner joins and outer joins. The syntax of SQL used here is for Oracle, however, it is very similar in all other databases like MySQL, MS SQLServer, Postgres, etc.. &lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;/div&gt;&lt;b&gt;&lt;span style="font-size: large;"&gt;Tables&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;We will create two tables by using the SQL statements below:&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;create table customer (cust_id number(4,0) not null, customer_name varchar2(60) not null);&lt;/span&gt;&lt;/em&gt;&lt;/li&gt;&lt;li&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;create table invoice (invoice_id number(4) not null, cust_id number(4) not null , invoice_total number(10,2) default 0.00, paid_ind char(1));&lt;/span&gt;&lt;/em&gt; &lt;/li&gt;&lt;/ol&gt;In the first SQL we create the table called Customer with the column names cust_id and customer_name. Observe that we do not want to store null values in each of the columns in the customer table. In the second SQL we create the table invoice, which has its columns and also the cust_id column from the customer table. This is how we delegate a specific invoice is&amp;nbsp;associated to a specific customer. &lt;br /&gt;&lt;br /&gt;Observe that one customer can have many invoices and hence we have a &lt;em&gt;&lt;strong&gt;one-many relationship&lt;/strong&gt;&lt;/em&gt; between customer and invoice tables. This implies that a customer may not have any invoices also i.e. a one-zero relationship beween the customer and invoice tables. &lt;br /&gt;&lt;br /&gt;We can make the above create SQLs complex by specifying the tablespace name (we are using the default tablespace assigned to the user you are logging on) and adding foreign key constraints to the cust_id in the invoice table to the customer table which will eliminate the input of data into the invoice table for which a cust_id is not existent in the customer table. &lt;br /&gt;&lt;br /&gt;A simple way to input data into the tables is to use the insert SQL statement which is given below:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;insert into customer values (100, 'Paradigm Solutions');&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;insert into customer values (102, 'Siemens Pvt Ltd');&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;insert into customer values (104, 'British Telecom');&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;commit;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now when we do a simple select from the customer table we get:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;CUST_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CUSTOMER_NAME &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;---------------------- ------------------------------------------------------------ &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Paradigm Solutions &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Siemens Pvt Ltd &lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; British Telecom &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;Now here are the SQL statements for inserting records into the invoice table.&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;insert into invoice values ( 8442, 102, 5430.00, 'Y');&lt;/em&gt;&lt;/span&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;insert into invoice values ( 8997, 102, 5430.00, 'Y');&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;insert into invoice values ( 8775, 102, 5430.00, 'N');&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;insert into invoice values (9876,100,2345.78,'N')&amp;nbsp;;&lt;/em&gt;&lt;/span&gt;&amp;nbsp; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;insert into invoice values (9886,100,345.00,'N');&amp;nbsp;&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;commit;&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&amp;nbsp; &lt;br /&gt;As an exercise, we leave to the reader to retrieve the records inserted into the table invoice. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;span style="font-size: large;"&gt;Inner and Outer Joins&lt;/span&gt;&lt;/strong&gt; &lt;br /&gt;&lt;br /&gt;To retrieve&amp;nbsp;customers and invoices for which there are invoices then we do an &lt;strong&gt;&lt;em&gt;inner&lt;/em&gt; &lt;em&gt;join&lt;/em&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;where&amp;nbsp; the sql is constructed by joining the column cust_id from the table customer and invoice: &lt;br /&gt;&amp;nbsp; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;select c.cust_id, &amp;nbsp;customer_name, i.invoice_id,&amp;nbsp; i.invoice_total, i.paid_ind &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;from customer c, invoice i where&amp;nbsp; c.cust_id= i.cust_id;;&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&amp;nbsp; &lt;br /&gt;gives results as: &lt;br /&gt;&amp;nbsp; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;CUST_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CUSTOMER_NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;INVOICE_ID&amp;nbsp;&amp;nbsp;INVOICE_TOTAL&amp;nbsp;&amp;nbsp;PAID_IND &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;---------------- --------------------------------------------------&amp;nbsp; ---------------------- ----------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;--------&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Paradigm Solutions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9876&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2345.78&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; N &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Paradigm Solutions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9886&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 345&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;N&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Siemens Pvt Ltd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8775&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5430&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; N&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Siemens Pvt Ltd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8997&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5430&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Y&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Siemens Pvt Ltd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8442&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5430&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Y&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;We can make our SQL criteria (the sql after the where keyword) complex by requesting only those which have not been paid by modifying as below:&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;where&amp;nbsp; c.cust_id= i.cust_id and i.paid_ind ='N' &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;which will return those invoices which have not paid for the customers who have invoices. &lt;br /&gt;&lt;br /&gt;Observe that we have used aliases for table names customer, invoice as c and i respectively. This eliminates any ambigous column names like cust_id being specified in the SQL and also eliminates typing the complete table name when referring the columns in the criteria or&amp;nbsp;in the select. &lt;br /&gt;&lt;br /&gt;The above was an example of inner join where we get the records when the exist in both tables. However, if you remember that we do not get the third customer - British Telecom from the table customer as it has no invoices associated it.&amp;nbsp; In order to obtain all the customer names and their invoices whether they exist or not we write an &lt;strong&gt;&lt;em&gt;outer join &lt;/em&gt;&lt;/strong&gt;as: &lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;select c.cust_id, customer_name, i.invoice_id &amp;nbsp;from customer c, invoice i where&amp;nbsp; c.cust_id= i.cust_id (+);&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;returns the results as shown below:&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;CUST_ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CUSTOMER_NAME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; INVOICE_ID &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;---------------------- ---------------------------------------------------- ---------------------- &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;span style="font-size: x-small;"&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Paradigm Solutions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9876 &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Paradigm Solutions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9886 &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Siemens Pvt Ltd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8775 &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Siemens Pvt Ltd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8997 &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;102&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Siemens Pvt Ltd&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8442 &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;strong&gt;&lt;em&gt;104&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; British Telecom &lt;/em&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Observe that in the outer join SQL we specify in the join (+) which is equivalent to writing as:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;&lt;strong&gt;select c.cust_id, customer_name, i.invoice_id&amp;nbsp; from customer c left outer join&amp;nbsp; invoice i on i.cust_id= c.cust_id ;&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The latter method is more readable and specifies whether it is left or right outer join while the (+) indicates already how the tables are joined and the right , left outer is dependent on which side of the = sign the (+) is assingned. &lt;br /&gt;&lt;br /&gt;It is nowadays in Object Oriented (OO) programming to understand both of these joins specifically when using an Object Relation Mapping (ORM) tools like Hibernate, topLink etc. Most of the time we are using an outerjoin to get the most relevant information and hence in Hibernate (we shall see in future articles) by default it uses outer join.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4331432086635454742-6053115379767380365?l=4circlesllc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://4circlesllc.blogspot.com/feeds/6053115379767380365/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4331432086635454742&amp;postID=6053115379767380365' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/6053115379767380365'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/6053115379767380365'/><link rel='alternate' type='text/html' href='http://4circlesllc.blogspot.com/2011/03/databases-basics.html' title='Databases - Basics'/><author><name>Rajeev</name><uri>http://www.blogger.com/profile/01677662936254968409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4331432086635454742.post-6416269224423878830</id><published>2011-01-12T08:16:00.000-08:00</published><updated>2011-03-29T14:25:20.020-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MySQL'/><category scheme='http://www.blogger.com/atom/ns#' term='Non Relational Databases'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev'/><category scheme='http://www.blogger.com/atom/ns#' term='Databases'/><category scheme='http://www.blogger.com/atom/ns#' term='Object Oriented Databases'/><category scheme='http://www.blogger.com/atom/ns#' term='4 Circles LLC'/><category scheme='http://www.blogger.com/atom/ns#' term='Oracle'/><category scheme='http://www.blogger.com/atom/ns#' term='4 Circles'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev Kuruganti'/><title type='text'>Databases - Introduction</title><content type='html'>&lt;b&gt;Database&lt;/b&gt;&lt;br /&gt;In the information age (which has started in 1940 or so when US census used the first computer), a database is referred to a silo of information which has data stored in a particular way so that stored data is relevant to make business decisions by employees. Databases are a specific type of models. Models are any storage repository (server) which stores data whether it is relational database, object-oriented database, flat or just files. &lt;br /&gt;&lt;br /&gt;In this article we confine ourselves to relational databases like MySQL, MS SQLServer20xx, Oracle, Sybase, MS Access and HSQLDB. These are the most common relational databases being used currently. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Non-Relational Databases&lt;/b&gt;&lt;br /&gt;Before we move onto relational databases; non-relational databases which are flat files, spreadsheets etc were big in their time. These demanded a lot of sort, find code by programmers to retrieve the data to the users. Consider the US phone book and the number 307-456-7892. In order to search the phone book to retrieve who is associated to this phone number the code (pseudo-code) would look something like: &lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;.... set up code&lt;br /&gt;do while (!eof(PhoneBook)) {&lt;br /&gt;if (recordPhoneNumber EQUALS '3074567892') then &lt;br /&gt;get out of the DO WHILE;&lt;br /&gt;nextRecord&lt;br /&gt;}&lt;br /&gt;... grab the record's last name and first name and send it back. &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;This means that for every phone number we will go through reading the file. Of course, if we had the file sorted by phone numbers a priori then it will be very easy to retrieve the name. Now if we were given the last name of the individual then to retrieve the phone number the logic would be the same. As you can already see this is CPU (Central Processing Unit)intensive and there are better ways of storing data, and retrieve in less time. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Object Oriented Databases&lt;/b&gt;&lt;br /&gt;Object Oriented(OO)Databases store objects. Objects have attributes and methods. These can be retrieved with OO languages like SmallTalk, Java, C++. An article [1] in reference section gives a short description of OO databases and their advantages and disadvantages. I urge the reader to skim the article, to get introduced to OO databases. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Relational Databases&lt;/b&gt;&lt;br /&gt;A relational database is two-dimensional and stores data in rows with the columns being attributes. It is akin to a spreadsheet. A spreadsheet(or a file)which stores particular data say the last name, first name, address and telephone number of individuals is referred to as a &lt;i&gt;table&lt;/i&gt; and each row in the spreadsheet is generally called &lt;i&gt;record&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;Consider our example in the flat file section where we need to retrieve the person associated with a telephone number. Now the pseudo code is reduced to a query in Structured Query Language (SQL) as:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;SELECT * FROM person WHERE telephoneNumber = 3074567892; &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The database engine then searches the table person for the record with the telephone number 3074567892 and returns the record. Now if there is no record matching the number then it will return zero records. &lt;br /&gt;&lt;br /&gt;In a database, a table can have index files which are files which sort the table on a specified column or concatenation of columns. When the query is sent to the table then the index file (in our example the telephoneNumber Index file) is used if it exists. If there is no index file then we are back to a full scan. Now, if we were given the last name and need to retrieve the phone number then the query is basically the same except for the where clause i.e. &lt;br /&gt;&lt;br /&gt;&lt;i&gt;SELECT * FROM person WHERE lastName ='COOK';&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;and the database engine will utilize the lastName index file for the above query. &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Primary Id&lt;/b&gt;&lt;br /&gt;Each table stores information regarding a primary unit in a structured way. For instance, a person can have many types of addresses email, business address, physical address, mail box address and sometimes a permanent address. This automatically lets a database designer think in terms of having a table which stores addresses and a table called say person which stores the last name, first name etc of the individual. &lt;br /&gt;&lt;br /&gt;To join the person table and the address table we define a unique identification for each person say SSN, DL # or just a sequence. This is then stored in both tables and then we can join the two tables to retrieve information of the person and their addresses. In other words, we relate the person table to the address table on the key sequenceNumber. Now the query will look &lt;br /&gt;&lt;br /&gt;&lt;i&gt;SELECT * FROM person, address WHERE person.sequenceNo = address.sequenceNo AND person.telephoneNumber = 3074567892 &lt;/i&gt;&lt;br /&gt;&lt;br /&gt;which will return all the records from both tables if they match in both tables for the specific telephone number. &lt;br /&gt;&lt;br /&gt;Index files are created on primary keys generally to speed the process of querying (searching). &lt;br /&gt;&lt;br /&gt;Now that the storage of data (models) has been introduced, we move onto other topics in programming and analysis. We now move into some SQL for creating, inserting data and also joins of tables in &lt;a href="http://4circlesllc.blogspot.com/2011/03/databases-basics.html"&gt;Databases Basics&lt;/a&gt;. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;REFERENCES&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;[1]An Introduction to &lt;a href="http://www.comptechdoc.org/independent/database/basicdb/dataobject.html"&gt;Object Oriented Databases&lt;/a&gt; article.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4331432086635454742-6416269224423878830?l=4circlesllc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://4circlesllc.blogspot.com/feeds/6416269224423878830/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4331432086635454742&amp;postID=6416269224423878830' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/6416269224423878830'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/6416269224423878830'/><link rel='alternate' type='text/html' href='http://4circlesllc.blogspot.com/2011/01/databases-introduction.html' title='Databases - Introduction'/><author><name>Rajeev</name><uri>http://www.blogger.com/profile/01677662936254968409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4331432086635454742.post-1744296344703958480</id><published>2010-12-08T10:07:00.000-08:00</published><updated>2011-03-28T15:02:29.785-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='secondaryTable 4circles secondary table blog'/><category scheme='http://www.blogger.com/atom/ns#' term='inheritance'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev'/><category scheme='http://www.blogger.com/atom/ns#' term='Databases'/><category scheme='http://www.blogger.com/atom/ns#' term='j2ee'/><category scheme='http://www.blogger.com/atom/ns#' term='4 Circles'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev Kuruganti'/><category scheme='http://www.blogger.com/atom/ns#' term='Hibernate'/><category scheme='http://www.blogger.com/atom/ns#' term='JPA'/><title type='text'>Hibernate-Secondary Table Annotation..</title><content type='html'>When using Hibernate with annotation SecondaryTable one needs to be careful how it is used while using the Discriminator. We assume that there is a table called Inventory which is the parent table which has common elements Id, createDate, modifiedDate, SKU#, productType. &lt;br /&gt;The other tables which are children of the Inventory table are TV_Inventory, DVD_inventory etc.. In this example we consider TV_Inventory which inherits from Inventory (in terms of objects). &lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Entity&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Table(name = "INVENTORY")&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Inheritance(strategy = InheritanceType.JOINED)&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@DiscriminatorColumn(name = "PRODUCT_TYPE", discriminatorType = DiscriminatorType.STRING, length = 20)&lt;br /&gt;@SequenceGenerator(name = "InventorySequence", sequenceName = "INV_SEQ", allocationSize = 1)&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;public abstract class Inventory {&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;// getters and setters with other annotations for the columns and relevant methods. &lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;}&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&amp;nbsp; &lt;br /&gt;Consider the child object associated with the table TV_INVENTORY. The outline is shown below: &lt;br /&gt;&amp;nbsp; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Entity&lt;br /&gt;@DiscriminatorValue("TV")&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@SecondaryTable(name = "TV_INVENTORY")&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;public class TVInventory extends Inventory {&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Location loc;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //LOCATION Table entity&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Other relevant columns, getters setters and methods. &lt;br /&gt;}&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;In using the above definition and annotations then we get the following error (assuming we are using Oracle DB). &lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;SELECT &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt; columns from Entities &amp;gt;&amp;gt;&amp;gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;from&lt;/em&gt;&lt;/span&gt;&lt;span style="color: blue;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;TV_Inventory invento0_,&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;INVENTORY ainvento0_1_,&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;LOCATION inventoryl2_ &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;where&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;invento0_.LOCATION_SEQ=inventoryl2_.LOCATION_SEQ(+) &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;and ainvento0_.INVENTORY_ID=ainvento0_1_.INVENTORY_ID &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;and ainvento0_.INVENTORY_ID=?&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;[10:55:46:218] org.hibernate.jdbc.AbstractBatcher DEBUG about to close PreparedStatement (open PreparedStatements: 1, globally: 1)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;[10:55:46:218] org.hibernate.util.JDBCExceptionReporter DEBUG could not load an entity: [com.hibernate.inv.model.aInventory#365746] &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;[The generated hibernate QUERY......]&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;java.sql.SQLException: ORA-00942: table or view does not exist&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: blue; font-size: x-small;"&gt;&lt;em&gt;at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;span style="font-size: small;"&gt;This can be fixed by NOT using secondaryTable. So now the TVInventory class is re-defined as&lt;/span&gt;:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Entity&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;@DiscriminatorValue("TV")&lt;/em&gt;&lt;/span&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Table(name="TV_INVENTORY")&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;public class TVInventory extends Inventory {&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Location loc; //LOCATION Table entity&lt;/span&gt;&lt;/em&gt;&lt;em&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;}&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: small;"&gt;and it works fine without errors. Now assume that for each TV in our inventory we have features of TV stored in another table, say TV_FEATURES. Then we can use the SecondaryTable annotation as follows:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;@Entity&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;@DiscriminatorValue("TV")&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;@Table(name="TV_INVENTORY")&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;@SecondaryTable(name="TV_FEATURES")&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;public class TVInventory extends Inventory { &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @OneToMany(fetch = FetchType.EAGER) &lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @JoinColumn(name="INVENTORY_ID")&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size: x-small;"&gt;&lt;em&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private List&lt;tvfeature&gt; tvFeatures;&lt;/em&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;}&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&amp;nbsp; &lt;br /&gt;The TVFeature class is defined as below: &lt;br /&gt;&amp;nbsp; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Entity&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;@Table(name="TV_FEATURES")&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;public class TVFeature {&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ///getters and setters for columns&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;}&lt;/span&gt;&lt;/em&gt; &lt;br /&gt;&lt;em&gt;&lt;span style="font-size: x-small;"&gt;&lt;/span&gt;&lt;/em&gt;&amp;nbsp; &lt;br /&gt;In the above scenarios we are not using any inheritance but joining the tables together on the inventory_id and defining the relationship between the TVInventory and TVFeature objects. So when using inheritance secondaryTable things can get a little sticky in hibernate.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4331432086635454742-1744296344703958480?l=4circlesllc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://4circlesllc.blogspot.com/feeds/1744296344703958480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4331432086635454742&amp;postID=1744296344703958480' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/1744296344703958480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/1744296344703958480'/><link rel='alternate' type='text/html' href='http://4circlesllc.blogspot.com/2010/12/hibernate-secondary-table-inheritance.html' title='Hibernate-Secondary Table Annotation..'/><author><name>Rajeev</name><uri>http://www.blogger.com/profile/01677662936254968409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4331432086635454742.post-9075794912721114903</id><published>2010-04-03T17:00:00.000-07:00</published><updated>2011-03-28T15:02:29.786-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev'/><category scheme='http://www.blogger.com/atom/ns#' term='4 Circles'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev Kuruganti'/><title type='text'>Binary Digits.</title><content type='html'>Consider the number 783 which can be obtained by:&lt;br /&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;td&gt;7 &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;10&lt;sup&gt;2&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=700&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;8 &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;10&lt;sup&gt;1&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;= 80&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;3 &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;10&lt;sup&gt;0&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;= 3&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;783&lt;sub&gt;10&lt;/sub&gt;&lt;/td&gt; &lt;td&gt;Total&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt; = 783&lt;sub&gt;10&lt;/sub&gt;&lt;/td&gt; &lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;So in decimal system we are counting how many 10s, 100s, 1000s, 10000s etc.. and then multiplying the the number depending on where it is positioned and adding them up. &lt;br /&gt;&lt;br /&gt;If we were to do the same to the base 8; then the above table will look as follows:&lt;br /&gt;&lt;br /&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt; &lt;td&gt;8&lt;sup&gt;3&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=512&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;4  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt; &lt;td&gt;8&lt;sup&gt;2&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=216&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;6  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt; &lt;td&gt;8&lt;sup&gt;1&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=48&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;7  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt; &lt;td&gt;8&lt;sup&gt;0&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=7&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1467&lt;sub&gt;8&lt;/sub&gt;&lt;/td&gt; &lt;td&gt;Total&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt; = 783&lt;sub&gt;10&lt;/sub&gt;&lt;/td&gt;  &lt;/table&gt;&lt;br /&gt;Now the number 783&lt;sub&gt;10&lt;/sub&gt; ~= 1467&lt;sub&gt;8&lt;/sub&gt;. This means that any number (like 783) can be written to any number base even its own. So in computers we are interested in binary as the switches in circuits are either ON or OFF. With this in mind then the number above (783) would be written in binary as follows:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;table border="1"&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;2&lt;sup&gt;9&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=512&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;2&lt;sup&gt;8&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=256&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;0  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt;&lt;td&gt;2&lt;sup&gt;7&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=0&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;0  &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;2&lt;sup&gt;6&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=0&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;0  &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;2&lt;sup&gt;5&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=0&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;0  &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;2&lt;sup&gt;4&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=0&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt;&lt;td&gt;2&lt;sup&gt;3&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=8&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt;&lt;td&gt;2&lt;sup&gt;2&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=4&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt; &lt;td&gt;x&lt;/td&gt;&lt;td&gt;2&lt;sup&gt;1&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=2&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1  &lt;/td&gt;&lt;td&gt;x&lt;/td&gt; &lt;td&gt;2&lt;sup&gt;0&lt;/sup&gt;&lt;/td&gt;&lt;td&gt;=1&lt;/td&gt;&lt;td&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt;&lt;td&gt;1100001111&lt;sub&gt;2&lt;/sub&gt;&lt;/td&gt; &lt;td&gt;Total&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt; = 783&lt;sub&gt;10&lt;/sub&gt;&lt;/td&gt;  &lt;/table&gt;&lt;br /&gt;&lt;br /&gt;This means that:&lt;br /&gt;1100001111&lt;sub&gt;2&lt;/sub&gt; ~=783&lt;sub&gt;10&lt;/sub&gt;&lt;br /&gt;&lt;br /&gt;Here is a sequence for those who have not figured out it is powers of 2 i.e.&lt;br /&gt;&lt;br /&gt;2&lt;sup&gt;0&lt;/sup&gt; = 1   = 1&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;1&lt;/sup&gt; = 2   = 10&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;2&lt;/sup&gt; = 4   = 100&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;3&lt;/sup&gt; = 8   = 1000&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;4&lt;/sup&gt; = 16  = 10000&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;5&lt;/sup&gt; = 32  = 100000&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;6&lt;/sup&gt; = 64  = 1000000&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;2&lt;sup&gt;4&lt;/sup&gt; = 128 = 10000000&lt;sub&gt;2&lt;/sub&gt;&lt;br /&gt;and so on... &lt;br /&gt;&lt;br /&gt;So now, gifting somebody $32.00 in decimal will be written in binary as $100,000&lt;sub&gt;2&lt;/sub&gt; and giving $64.00 = $1,000,000&lt;sub&gt;2&lt;/sub&gt; which is a LOT OF MONEY... :).  &lt;br /&gt;&lt;br /&gt;As the joke goes: There are 10 kinds of people, the kind that understand binary numbers and those who do not.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4331432086635454742-9075794912721114903?l=4circlesllc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://4circlesllc.blogspot.com/feeds/9075794912721114903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4331432086635454742&amp;postID=9075794912721114903' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/9075794912721114903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/9075794912721114903'/><link rel='alternate' type='text/html' href='http://4circlesllc.blogspot.com/2010/04/counting-in-2s-or-binary-numbers.html' title='Binary Digits.'/><author><name>Rajeev</name><uri>http://www.blogger.com/profile/01677662936254968409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4331432086635454742.post-7309747652768835112</id><published>2010-01-10T06:03:00.000-08:00</published><updated>2011-03-28T15:02:29.787-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='writers'/><category scheme='http://www.blogger.com/atom/ns#' term='Word Frequency'/><category scheme='http://www.blogger.com/atom/ns#' term='word'/><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='students'/><category scheme='http://www.blogger.com/atom/ns#' term='word count'/><category scheme='http://www.blogger.com/atom/ns#' term='total number of words'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev'/><category scheme='http://www.blogger.com/atom/ns#' term='frequency'/><category scheme='http://www.blogger.com/atom/ns#' term='4 Circles'/><category scheme='http://www.blogger.com/atom/ns#' term='Rajeev Kuruganti'/><category scheme='http://www.blogger.com/atom/ns#' term='English'/><title type='text'>4 Circles releases Word Frequency..</title><content type='html'>&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_evsXNXoi9tM/S3Xflr8iiVI/AAAAAAAAAAM/EdkeT-7e1NI/s1600-h/WordFreq_sc1.JPG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 320px; height: 202px;" src="http://4.bp.blogspot.com/_evsXNXoi9tM/S3Xflr8iiVI/AAAAAAAAAAM/EdkeT-7e1NI/s320/WordFreq_sc1.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5437497963664542034" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.4circlesllc.com/"&gt;4 Circles&lt;/a&gt; releases its application 'Word Frequency v1.1'. &lt;br /&gt;&lt;br /&gt;This application counts the number of words in your essay and tells you the frequency of each word in a table. This application as can be seen in the screen shot above is simple to use and helpful for bloggers, writers, journalists, students and speech writers. The application has 1 box for the text to be copied and pasted while clicking the button will count the total number of words in the essay. &lt;br /&gt;&lt;br /&gt;This application is written in JDK 1.6, and runs on JRE 1.6.x or above. The user needs to copy the text and place in the text box and click on the button to get the frequency in the grid. Please download the software here:&lt;br /&gt;&lt;a href="http://www.4circlesllc.com/applications"&gt;Word Frequency&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_evsXNXoi9tM/S3Xgaf_vJSI/AAAAAAAAAAU/-wjaAzAqcVo/s1600-h/WordFreq_sc2.JPG"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 200px; height: 140px;" src="http://4.bp.blogspot.com/_evsXNXoi9tM/S3Xgaf_vJSI/AAAAAAAAAAU/-wjaAzAqcVo/s200/WordFreq_sc2.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5437498870989792546" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4331432086635454742-7309747652768835112?l=4circlesllc.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://4circlesllc.blogspot.com/feeds/7309747652768835112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=4331432086635454742&amp;postID=7309747652768835112' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/7309747652768835112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4331432086635454742/posts/default/7309747652768835112'/><link rel='alternate' type='text/html' href='http://4circlesllc.blogspot.com/2010/01/4-circles-releases-word-frequency.html' title='4 Circles releases Word Frequency..'/><author><name>Rajeev</name><uri>http://www.blogger.com/profile/01677662936254968409</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_evsXNXoi9tM/S3Xflr8iiVI/AAAAAAAAAAM/EdkeT-7e1NI/s72-c/WordFreq_sc1.JPG' height='72' width='72'/><thr:total>2</thr:total></entry></feed>
