hello all
i need to fetch data from two column let me tell how i like to fetch this,i have two table first column is ledger in which there is groupname,balance.now in seconed table whic name is groupcreate,here is under and name column heare you *****can create your own group type so that in groupcreate i stored groupname and there name.*****

now this name is stored in ledger in column group now i want to fetch value from ledger how i can do that how i know value come from ldger is same group

bankaccount is in ledger table if here is durgesh name in groupname and it group stored in groupcreate table in under then it should be also fetched from ledger how i do this

Edited 3 Years Ago by durgesh1: to text chane

and what exactly is your question?
how to do this in Java? how to do this in sql? ... ?
are you using foreign keys?

i like to do this in java swing i am not using any foreign keys

by the sound of it, you should be.
Java Swing can not help you in getting information from a database, it can only help displaying it.
take a look at JDBC, JPA or Hibernate


as stultuske already stated this can simply be done with the help of JDBC (ok, JPA 2 is more powerful but also somewhat more sophisticated.

If you are adept in SQL you can create a select statement like this one:

select all_columns_you_need from table1 inner join table2 where some_restrctions;
-- above is SQL and not Java

Depending on your database system you need to add ON clause to the join.

If you create a result set that way, you only need a java while loop like this one:
.... // here you have to create a statement and a result set object first, see JDBC description

while (resultSet.next()) { // get your column values, e.g:
  string ledger = resultSet.getString("Ledger");
  // process your column values here

If you post your specific database, all column names and their data types of both tables, I would be able to guide you in a more detailed way.

-- 1stDAN

Hi again,

if you don't like to work with foreign keys (such stuff has to be carefully defined within your database tables, if not, joins probably don't work), you can't make use of inner join.

This means that you have to program two nested while loops. Outer loop runs over the master table, inner loop runs over the slave table / child table, for you quite likely have a one-to-many relationship between both tables.

-- 1stDAN

thanks 1stDAN for your advice i try this but here is one problem that some name is repeated in ledger table like bank account or groupname that is in groupcreate table and also stored in ledger table
createe by user i want only one
value to print not all value
and print one time of name of group will you help me again


this is easy, for example you may have table1 and table2, both have a column named ledger:
select t1.ledger, plus_further_columns from table1 t1 inner join table2 t2 on t1.joinColumn = t2.joinColumn ...

This only shows the value of column ledger from table1.

(Depending on your database system and also correctly defined foreign keys the on-clause might not be necesseary.)

It would be really easier if you post the correct names of both tables and all their correct column names and also datatypes.

Edited 3 Years Ago by 1stDAN

i use this but it show repetive value
durgesh <----
i like this should print one time only

Well durgesh1, above is hardly to understand for it is not the true output of a SQL statement. Why not following my suggestion "It would be really easier if you post the correct names of both tables and all their correct column names and also datatypes."? You may also show your own select statement and the REAL result of your own select statement.

Thanks, 1stDAN

Edited 3 Years Ago by 1stDAN

This article has been dead for over six months. Start a new discussion instead.