java - Using one query in another in JDBC programming -


i understand how on paper in sql, having trouble implementing in java (this first time programming jdbc stuff)

for example, database consists of:

movie(code, title, publisher)

customer(custno, name)

borrowed(custno, code)

and want find name of customers borrowed every movie pubisher abc

string no_of_abc_movies = "select count(publisher), publisher movie, movie.publisher = 'abc'";  string no_of_cust_abc_movies = "select count(name), name customer, borrowed, movie, customer.custno = borrowed.custno , borrowed.code = movie.code , movie.publisher = 'abc'";   string query = "select name" +                         " name customer, borrowed, movie" +                         " customer.custno = borrowed.custno and" +                         " borrowed.code = movie.code and" +                         " movie.publisher = 'abc' and" + " "                          no_of_cust_abc_movies + " = " + no_of_abc_movies; 

this isn't exact database working with, query work , print out names of people borrowed movies abc without last line, says have error in sql syntax last line guess don't know how use 1 query within another.

it depends on dbms, every sql variant i've seen requires parens around subqueries.

try like:

...  " movie.publisher = 'abc' , (" no_of_cust_abc_movies + ") = (" + no_of_abc_movies + ")"; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -