Wednesday, 29 October 2014

How to write select query for retrive datas or values from more than a table using join query in android programmatically

Log.v("tag", "retriveDetails_Database()---------------------------------") ;
       
        // LIKE , GROUPBY , SUM , HAVING , ORDERBY , COUNT , DISTINCT , UNION , UNIONALL 
       
         String selectQuery = "select e.empmobile from employeetable e inner join labourtable v on e.salary == v.salary" ;
       
         String SELECT_QUERY = "SELECT * FROM employeetable t1 INNER JOIN labourtable t2 ON t1.salary = t2.salary GROUP BY t1.empname";
       
       
         //The following SQL statement selects all employeetable with a empcity starting with the letter "s":
         String selectQueryLike = "select * from employeetable where empcity LIKE '%I' ";
       
         //The following SQL statement selects all employeetable with a empcity containing the pattern "nna":
         String selectQueryLikeTwo = "select * from employeetable where empcity LIKE '%ROD%' ";
       
       
         //Using the NOT keyword allows you to select records that does NOT match the pattern.
         //The following SQL statement selects all customers with a Country NOT containing the pattern "land":
         String selectQueryLikeThree = "select * from employeetable where empcity NOT LIKE '%LOR%' ";
       
       
         //SQL statement selects only the distinct values from the "City" columns from the "Customers" table:
         String queryDistinct = " SELECT DISTINCT empcity FROM employeetable " ;

       
         SQLiteDatabase db ;
         TestingDBHelper dbHelper = new TestingDBHelper(getApplicationContext()) ;
         db = dbHelper.getWritableDatabase() ;
       
        Cursor c = db.rawQuery(queryDistinct, null);
       
        Log.v("tag", "cursor:"+c.getCount() ) ;
           
        while( c.moveToNext() )
        {
           
            // String dataResult = c.getString(c.getColumnIndex(TestingTableEmployee.COLUMN_ID)) ;
            //String dataResult = c.getString(c.getColumnIndex(TestingTableEmployee.DATA5_EMPCITY)) ;
            //String dataResult = c.getString(c.getColumnIndex(TestingTableEmployee.DATA3_EMPMOBILE)) ;
            String dataResult = c.getString(c.getColumnIndex(TestingTableEmployee.DATA6_EMPSALARY)) ;
           
             Log.v("tag", "dataResult:"+dataResult) ;
        }
        c.close() ;
        db.close() ;
       
        //-----------------------------------------------------------------------------------------------------------
       
         String querySum = "SELECT SUM(salary) FROM employeetable;" ;
         String queryCount = "SELECT COUNT(*) FROM employeetable;" ;
       
         c = db.rawQuery(querySum, null);
       
        Log.v("tag", "cursor:"+c.getCount() ) ;
       
        if ( c.moveToFirst() ) {
           
            String data = c.getString(0) ;
            Log.v("tag", "data:"+data) ;
        }
        c.close() ;
        db.close() ;
       
        //-----------------------------------------------------------------------------------------------------------