0

I attach one image of my problem:

enter image description here

  1. In Testing jFrame jTextField I will insert customer id then after pressing ok button query will select and collect information related to that customer.Then it will show in the jTableModel.
  2. I attach my database image.
  3. Error is "SQL code cannot be executed".
5
  • I do not know join query.Sorry Commented Jun 24, 2014 at 7:57
  • But the tables are related themselves? Or they are totally unrelated? Commented Jun 24, 2014 at 7:59
  • related to each other with certain column.. Commented Jun 24, 2014 at 8:00
  • A tutorial on SQL joins might help:sqlzoo.net/wiki/The_JOIN_operation Commented Jun 24, 2014 at 8:06
  • @Devendra ok, this is the frequent case. I wrote a simple example for that. Commented Jun 24, 2014 at 8:18

5 Answers 5

2

You can do like this (without Join):

SELECT   papers.paper_list,papers_rate.monday,papers_rate.tuesday,
papers_rate.wednesday,papers_rate.thrsday,papers_rate.friday,
papers_rate.saturday,papers_rate.sunday,magzines.magzine_name,magzines_rate.rate 
FROM papers,papers_rate,magzines,magzines_rate 
WHERE example_table.customer_id = ? AND other conditions"

This syntax is, in effect, a simple INNER JOIN. Some databases treat it exactly the same as an explicit JOIN. The WHERE clause tells the database which fields to correlate, and it returns results as if the tables listed were combined into a single table based on the provided conditions.(http://www.techrepublic.com/article/sql-basics-query-multiple-tables/)

Sign up to request clarification or add additional context in comments.

1 Comment

@Devendra u've edited ur question so u must should use joins if the tables are related.
2

You need to join the tables properly.
Like this:

SELECT
   paper_list,monday,tuesday,wednesday,thrsday,friday,saturday,sunday,magzine_name,rate 
FROM papers

LEFT JOIN papers_rate
    ON papers_rate.paperId = papers.id

LEFT JOIN magzines
     ON magzines.paperId = papers.id

LEFT JOIN magzines_rate 
     ON magzines_rate.magazineId = magzines.id

WHERE customer_id = ?"

If you do an inner join, all your results will vanish if you don't have a magazine_rate for example...

And check your spelling.
You're writing thrsday instead of thursday and magzine instead of magazine...

PS: And where does customer_id come from ?

Comments

1

Use joins to select multiple column from multiple tables. Refer this to get an understanding about the join and for join examples.

Note: There should be a common field between two tables to perform join operation

Comments

1

If the tables are related you must use JOIN: let's see an example (I don't know your tables fields, so I'll invent a custom example). Think about person and pet tables; the person tables could contain these fields:

Person (personID, first_name, last_name, age)

the pet table could contain these other fields:

Pet (petID, name, age, personID)

The personID field in the pet table identifies the owner of the pet. It is a simple 1:N relation. To select some values from these two tables you must do something like:

SELECT Person.first_name, Person.last_name, Pet.name
FROM Person INNER JOIN Pet ON
Person.personID = Pet.personID
WHERE Person.age > 30

This is just an example, clearly. And the INNER JOIN is just a join type (there are several join methods). Here you can find some documentation concerning these issues.

Comments

1

You need to either use a Join clause (... FROM papers JOIN papers_rate ON papers.[id_column] = papers_rate.[foreign_key]) or use an equi-join (replace JOIN...ON clause with a condition in the WHERE clause) (... FROM papers,papers_rate WHERE papers.[id] == papers_rate.[foreign_key])

Could you please post the schema of your tables?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.