I am trying to create an android app and I have to do the follwoing:
I have two tables bill with barcode and amount columns and table billpayments with barcode and payamount columns.
How can I select from table billpayments amount where barcore = table bill barcode???
This is my code
function getItem1(flatname) {
var total = 0;
var payment = 0;
var previous = 0;
$.mobile.notesdb.transaction(function(t) {
t.executeSql('SELECT barcode, buildingcode, buildingaddress, flatname, flatdescription, entryseason, period, amount FROM bill WHERE flatname = ?',
[flatname],
function(t, result) {
var i,
len = result.rows.length,
row,
rowb;
for (i = 0; i < len; i += 1) {
row = result.rows.item(i);
var html = '<input type="checkbox" name="code_'+ i +'" id="code_'+ i +'" value="' + row.amount + '"/><label for="code_'+ i +'">' + row.period +'..........'+ row.amount+'</label></br>';
$('#Code').append($(html));
total = total + row.amount;
function previousPayments() {
$.mobile.notesdb.transaction(function(t) {
t.executeSql('SELECT barcode, amount FROM billpayments WHERE barcode=?',[row.barcode],
function(t, resultpayment) {
var ii,
lenb = resultpayment.rows.length,
rowb;
for (ii = 0; ii < lenb; ii += 1) {
var rowb = resultpayment.rows.item(ii);
$('#displayflat article').append($('<p>' + rowb.barcode + '</p>'));
previous = previous + rowb.amount;
}
});
});
}
previousPayments();
$('#displayflat article').append($('<p>' + row.barcode + '</p>'));
}
Join the tables on the barcode column. http://www.w3schools.com/sql/sql_join.asp this should explain joins. I think you want an inner join (or just join, same thing).
Check out the site to make sure you get exactly what you want.