mysql - how to select on same table twice In one query or round-trip? -
ok here code-snipet of have tried:
private static void checkforchanges(mysqlconnection connection) { datetime hair = datetime.parse(smartstyledataset.tables["hair"].compute("max(lastupdated)", null).tostring()); datetime cloths = datetime.parse(smartstyledataset.tables["cloths"].compute("max(lastupdated)", null).tostring()); datetime accessories = datetime.parse(smartstyledataset.tables["accessories"].compute("max(lastupdated)", null).tostring()); datetime cosmetics = datetime.parse(smartstyledataset.tables["cosmetics"].compute("max(lastupdated)", null).tostring()); list<string>[] newrows = { new list<string>(), new list<string>(), new list<string>(), new list<string>() }; using (var command = connection.createcommand()) { connection.open(); command.commandtext = "select * " + "from smartstyle.table_changes_logger " + "where updated > @accessories , table = 'accessories' ; " + "select * " + "from smartstyle.table_changes_logger " + "where updated > @cosmetics , table = 'cosmetics' ; " + "select * " + "from smartstyle.table_changes_logger " + "where updated > @cloths , table = 'cloths' ; " + "select * " + "from smartstyle.table_changes_logger " + "where updated > @hair , table = 'hair'"; command.parameters.add("@cloths", mysql.data.mysqlclient.mysqldbtype.timestamp).value = cloths.tostring("yyyy-mm-dd hh:mm:ss"); command.parameters.add("@hair", mysql.data.mysqlclient.mysqldbtype.timestamp).value = hair.tostring("yyyy-mm-dd hh:mm:ss"); command.parameters.add("@accessories", mysql.data.mysqlclient.mysqldbtype.timestamp).value = accessories.tostring("yyyy-mm-dd hh:mm:ss"); command.parameters.add("@cosmetics", mysql.data.mysqlclient.mysqldbtype.timestamp).value = cosmetics.tostring("yyyy-mm-dd hh:mm:ss"); using (var reader = command.executereader()) { { while (reader.read()) { newrows[0].add(reader.getstring(1)); newrows[1].add(reader.getstring(2)); newrows[2].add(reader.getstring(3)); newrows[3].add(reader.getstring(4)); } } while (reader.nextresult()); } } }
but doesn't work following generic error mysql dont understand you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'table = 'accessories' ; select * smartstyle.table_changes_logger upd' @ line 1
you need escape reserved words in mysql table
backticks.
select * smartstyle.table_changes_logger updated > @accessories , `table` = 'accessories'
Comments
Post a Comment