Results 1 to 17 of 17
Thread: Sql Query
- 02-17-2009, 11:08 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Sql Query
Hi,
I'm working on a client management system.
in my database i have a customer table a product table so if the customer clicks details he gets the customer table and if he clicks on last bought products for example he gets the product table
What is a better design to have a long table containing both the customer and product details and get one part at a time or to have two tables and use two sql queries to get the data?
- 02-18-2009, 02:01 PM #2
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
you can manipulate both tables together
like
customer table will contain all the columns of the product table and every row will have all the details about customer..
this is possible but not a good way to use database.
you will increase processing time also.
- 02-18-2009, 03:21 PM #3
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Any more info on that, can you elaborate on your answer a bit?
- 02-18-2009, 06:18 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
I'm sorry, but this is a Java Forum. The dtabase header implies JDBC, i.e. Connection, DriverManager, DatabaseMetaData, Statement PreparedStatement, CallableStatement, ResultSet ResultSetMetaData, etc. That question is a pure SQL question, you would get better help at an actual SQL forum.
- 02-18-2009, 10:45 PM #5
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Your probably right but it was worth a shot.
- 02-19-2009, 06:48 AM #6
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
hi nomad
suppose u hv two tables
customer - carries info about customer, would hv some id(PK)
and product - carries product info of a perticular customer with their PK.
you can create a single table
say, cust-pro
which will hav all the column of both tables
like
cust_id, cust_name, prod_id, prod_name
now you can get the records with cust id.
i think you are doing
select * from product where cust_id = some_id;
now you can do
select * from cust-pro where cust_id = some_id;
you will get all the info about the product and customers
thanks
/\/
- 02-19-2009, 04:48 PM #7
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
So basically you went for the idea of having one large table containing all the data from both tables and use sql queries to get the pieces of info i require,why is that a bad way to use a database?
it just seems very ineffective requiring multiple queries for every detail almost and also seems kinda strange logic to fill one have of the table then find it again later and fill the other there must be a simpler solution or am i crazy ? :)
- 02-19-2009, 08:00 PM #8
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
It's called "join". Like I said, go to an SQL forum.
- 02-20-2009, 12:36 AM #9
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Well gee thanks for banishing me...
- 02-20-2009, 08:03 AM #10
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
I'm not banishing you. I'm trying to help you. The advice you've gotten here, so far, has not been good. I could, possibly, tell you enough to get you through this problem, but that doesn't mean it would be the best advice. You will get much better help at an SQL forum.
Do you expect a nurse to be able to tell you what plants to grow, and how to process them in order to come up with the cloth that makes a cast? They use casts, so they must know how to make them, right? No, you don't think that. So why do you think you'll get good SQL advice at a Java forum? We use DBs, so we must be experts in them, right?
- 02-20-2009, 09:20 AM #11
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
- 02-20-2009, 09:48 AM #12
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
- 02-20-2009, 10:01 AM #13
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Oh, damn it, here:
Edit: BTW, those equals where clauses (especially when combined with the selection fields above) perform an implicit (and I say implicit because you are not using the "command" join in the query, but it is, actually rather explicit) join.Java Code:Customer_Table --------------- Customer_Id Further_Fields (Such as address, name, billing info, etc) Product_Table -------------- Product_Id Further_Fields (Such as product name, cost, model, description, etc) Purchases ---------- Customer_Id -- Foreign_Key Product_Id -- Foreign_Key Further_Info (such as date and amount purchased, etc.) Select Cust.Customer_Id, Cust.Further_Fields, Prod.Product_Id, Prod.Further_Fields, Buy.Further_Info From Customer_Table Cust, Product_Table Prod, Purchases Buy Where Cust.Customer_Id = whatever And Buy.Customer_Id = Cust.Customer_Id And Prod.Product_Id = Buy.Product_Id
As I said, I could probably help you through this one, but the right place to ask this question is on an SQL forum. Just some people here felt the need to argue, so they needed proving wrong.Last edited by masijade; 02-20-2009 at 10:08 AM.
- 02-20-2009, 10:40 AM #14
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
- 02-20-2009, 11:29 AM #15
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
You need to read it carefully. He asked whether it was better to have multiple tables and queries or one large one and one query. And it is always better to have multiple tables when information will have to be repeated by having it in a single table, which is the case here.
Which makes the answer 50/50, as it is best to have multiple tables, but still use one query. Which, once again, is an SQL question and has nothing to do with Java.
- 02-20-2009, 01:39 PM #16
Member
- Join Date
- Nov 2008
- Posts
- 15
- Rep Power
- 0
Thanks masijade exacly what i needed!
if only you had done that earlier...
- 02-20-2009, 01:58 PM #17
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
I need help with a query.
By Daredemo in forum JDBCReplies: 1Last Post: 08-13-2008, 05:16 AM -
Help in Query
By geeta_ravikanti in forum JDBCReplies: 0Last Post: 03-31-2008, 01:16 PM -
Using sql:query tag
By Java Tip in forum Java TipReplies: 0Last Post: 01-15-2008, 03:13 PM -
Using sql:query tag
By Java Tip in forum Java TipReplies: 0Last Post: 01-14-2008, 09:31 AM -
An interface query !!
By ajaygargnsit in forum New To JavaReplies: 3Last Post: 12-22-2007, 05:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks