Monday, May 20, 2013

Splash Screen Android

Create Splash Screen In Android

Creating splash is a three step simple procedure

  1. Create XML splash.xml and copy this code
     <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#FFFFFF"
    android:layout_gravity="center">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:src="@drawable/splash"
        android:scaleType="centerInside"
android:gravity="center"/>

</LinearLayout>

  2. Create JAVA file splash.java and copy this code

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.view.Window;

public class SplashActivity extends Activity {
private final int SPLASH_DISPLAY_LENGTH = 3000;
protected void onCreate(Bundle savedInstanceState)
{
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
}

@Override
protected void onResume()
{
super.onResume();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
// Obtain the sharedPreference, default to true if not available
boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);

if (isSplashEnabled)
{
new Handler().postDelayed(new Runnable()
{
@Override
public void run()
{
//Finish the splash activity so it can't be returned to.
SplashActivity.this.finish();
// Create an Intent that will start the main activity.
Intent mainIntent = new Intent(splash.this, MainActivity.class);
SplashActivity.this.startActivity(mainIntent);
}
}, SPLASH_DISPLAY_LENGTH);
}
else
{
// if the splash is not enabled, then finish the activity immediately and go to main.
finish();
Intent mainIntent = new Intent(splash.this, MainActivity.class);
SplashActivity.this.startActivity(mainIntent);
}
}
}

 3. Now third and final step open AndroidManifest.xml file and copy this code under application tag

<activity
            android:name=".splash"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
</activity>

And your work is done, splash is ready to explode....


Please leave comment if any problem occurs...............................

  





Tuesday, April 23, 2013

Download a File In Android From Remote Server

Download a File In Android From Remote Server


In Your class file put add this code 


package com.facebook.samples.sessionlogin;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button; 


public class HTTPTest extends Activity {
String dwnload_file_path = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-snc6/187259_10000060421658402_744490318028_q.jpg";
    String dest_file_path = "/sdcard/dwnloaded_file.png";
    Button b1;
    ProgressDialog dialog = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
         
        b1 = (Button)findViewById(R.id.Button01);
        b1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                 
                dialog = ProgressDialog.show(HTTPTest.this, "", "Downloading file...", true);
                 new Thread(new Runnable() {
                        public void run() {
                             downloadFile(dwnload_file_path, dest_file_path);
                        }
                      }).start();               
            }
        });
    }
     
    public void downloadFile(String url, String dest_file_path) {
          try {
              File dest_file = new File(dest_file_path);
              URL u = new URL(url);
              URLConnection conn = u.openConnection();
              int contentLength = conn.getContentLength();
              DataInputStream stream = new DataInputStream(u.openStream());
              byte[] buffer = new byte[contentLength];
              stream.readFully(buffer);
              stream.close();
              DataOutputStream fos = new DataOutputStream(new FileOutputStream(dest_file));
              fos.write(buffer);
              fos.flush();
              fos.close();
              hideProgressIndicator();
               
          } catch(FileNotFoundException e) {
              hideProgressIndicator();
              return; 
          } catch (IOException e) {
              hideProgressIndicator();
              return; 
          }
    }
     
    void hideProgressIndicator(){
        runOnUiThread(new Runnable() {
            public void run() {
                dialog.dismiss();
            }
        });  
    }
}

In your manifestation file add permission for

    
    <uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    

In your xml file add 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="File Download Demo from Coderzheaven \n\nFile to download : http://coderzheaven.com/sample_folder/sample_file.png \n\nSaved Path : sdcard/\n"
    />
<Button
    android:text="Download File"
    android:id="@+id/Button01"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</Button>
</LinearLayout>


And you are good to go.........

Thursday, April 18, 2013

PHP: LOOP THROUGH EACH STRING LINE IN A TEXTAREA


To loop through all the string inputs entered on a new line for a textarea control is not particularly challenging and uses basic array functionality to achieve this.
To see the code in action:
//trim off excess whitespace off the whole
$text = trim($_POST['textareaname']);

//explode all separate lines into an array
$textAr = explode("\n", $text);

//trim all lines contained in the array.
$textAr = array_filter($textAr, 'trim');

//loop through the lines
foreach($textAr as $line){
echo "$line";
}

Uploading files to HTTP server using POST. Android SDK.

On Android Class just paste the code


HttpURLConnection connection = null;
DataOutputStream outputStream = null;
DataInputStream inputStream = null;

String pathToOurFile = "/data/file_to_send.mp3";
String urlServer = "http://192.168.1.1/handle_upload.php";
String lineEnd = "\r\n";
String twoHyphens = "--";
String boundary =  "*****";

int bytesRead, bytesAvailable, bufferSize;
byte[] buffer;
int maxBufferSize = 1*1024*1024;

try
{
FileInputStream fileInputStream = new FileInputStream(new File(pathToOurFile) );

URL url = new URL(urlServer);
connection = (HttpURLConnection) url.openConnection();

// Allow Inputs & Outputs
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);

// Enable POST method
connection.setRequestMethod("POST");

connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);

outputStream = new DataOutputStream( connection.getOutputStream() );
outputStream.writeBytes(twoHyphens + boundary + lineEnd);
outputStream.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + pathToOurFile +"\"" + lineEnd);
outputStream.writeBytes(lineEnd);

bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
buffer = new byte[bufferSize];

// Read file
bytesRead = fileInputStream.read(buffer, 0, bufferSize);

while (bytesRead > 0)
{
outputStream.write(buffer, 0, bufferSize);
bytesAvailable = fileInputStream.available();
bufferSize = Math.min(bytesAvailable, maxBufferSize);
bytesRead = fileInputStream.read(buffer, 0, bufferSize);
}

outputStream.writeBytes(lineEnd);
outputStream.writeBytes(twoHyphens + boundary + twoHyphens + lineEnd);

// Responses from the server (code and message)
serverResponseCode = connection.getResponseCode();
serverResponseMessage = connection.getResponseMessage();

fileInputStream.close();
outputStream.flush();
outputStream.close();
}
catch (Exception ex)
{
//Exception handling
}

Now on php(Server side) page paste the code 


<?php
$target_path  = "./";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
 echo "The file ".  basename( $_FILES['uploadedfile']['name']).
 " has been uploaded";
} else{
 echo "There was an error uploading the file, please try again!";
}
?>



Friday, April 12, 2013

Generate Hash Key For Facebook 


In order to generate key hash you need to follow some easy steps.

1) Download Openssl from: http://code.google.com/p/openssl-for-windows/downloads/list

2) Make a openssl folder in C drive

3) Extract Zip files into openssl folder

4) Copy the File debug.keystore from .android folder in my case (C:\Users\SYSTEM.android) and paste into JDK bin Folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin)

5) Open command prompt and give the path of JDK Bin folder in my case (C:\Program Files\Java\jdk1.6.0_05\bin).

6) Copy the code and hit enter keytool -exportcert -alias androiddebugkey -keystore debug.keystore > c:\openssl\bin\debug.txt

7) Now you need to enter password, Password = android.

8) See in openssl Bin folder you will get a file with the name of debug.txt

9) Now either you can restart command prompt or work with existing command prompt

10) comes to C drive and give the path of openssl Bin folder

11) copy the following code and paste openssl sha1 -binary debug.txt > debug_sha.txt

12) you will get debug_sha.txt in openssl bin folder

13) Again copy following code and paste openssl base64 -in debug_sha.txt > debug_base64.txt

14) you will get debug_base64.txt in openssl bin folder

15) open debug_base64.txt file Here is your Key hash.

Hope This Help....................

Tuesday, March 5, 2013

Wamp Server common error "Could not execute menu item (internal error)

Wamp Server common error "Could not execute menu item (internal error)[Exception] Could not perform service action: The service has not been started".

Solution !:
Please make sure none of the following services is running on your system.

  1. IIS
  2. Skype
  3. NOD32
  4. Eset
  5. Internet optimizer
  6. Google Accelerator
  7. any database server
  8. any web server
If you are using any one of them , close it or uninstall it then select "restart all services" from WAMP menu.

Solution 2:

Under Apache open the " httpd.conf " and change the lines

#Listen 12.34.56.78:80
Listen 80 

To

#Listen 12.34.56.78:80
Listen 8080

Save the file and restart the server and you are good to go 

check by typing 127.0.0.1 or localhost in your browser. 

Monday, February 25, 2013

WAMP Server ERROR “Forbidden You don't have permission to access /phpmyadmin/ on this server.”


WAMP Server ERROR

Forbidden You don't have permission to access/phpmyadmin/ on this server.



If you are getting this error and you want to overcome it just follow the basic step 

Go to Folder C:\wamp\alias.
 Open the file phpmyadmin.conf 
And Edit

<Directory "c:/wamp/apps/phpmyadmin3.5.1/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>
To

<Directory "c:/wamp/apps/phpmyadmin3.5.1/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
        Order Allow,Deny
    Allow from all
</Directory>

And your problem is solved......












Friday, February 22, 2013

SQL to Select a random row from a database table


SQL to Select a random row from a database table


There are lots of ways to select a random record or row from a database table. Here are some example SQL statements that don't require additional application logic, but each database server requires different SQL syntax.

Select a random row with MySQL:

SELECT column FROM table
ORDER BY RAND()
LIMIT 1

Select a random row with PostgreSQL:

SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1

Select a random row with Microsoft SQL Server:

SELECT TOP 1 column FROM table
ORDER BY NEWID()

Select a random row with IBM DB2

SELECT column, RAND() as IDX 
FROM table 
ORDER BY IDX FETCH FIRST 1 ROWS ONLY

Select a random record with Oracle:

SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1

Wednesday, February 20, 2013

Database Mysql Basics Everyone Should Know

SQL Queries and Database Basics

Here we are going to understand database basics, starting with creating simple tables.

Create the following tables







Queries Based on tables

Simple Queries:


     Prob: List all the employee details.

     Sol : SQL > Select * from employee;

     Prob: List all the department details

     Sol: SQL > Select * from department;

     Prob: List all job details

     Sol: SQL > Select * from job;

     Prob: List all the locations

     Sol: SQL > Select * from loc;

     Prob: List out first name,last name,salary, commission for all employees

     Sol: SQL > Select first_name, last_name, salary, commission from employee;

     Prob: List out employee_id,last name,department id for all  employees and rename    
     employee id as “ID  of the employee”, last name as “Name of the employee”,
     department id as  “department  ID”

     Sol: SQL > Select employee_id “id of the employee”, last_name “name", department 
     id as “department id” from employee;

     Prob: List out the employees anuual salary with their names only.

     Sol: SQL > Select last_name, salary*12 “annual salary” from employee

Where Conditions:

    Prob: List the details about “SMITH”

    Sol:  SQL > Select * from employee where last_name=’SMITH’;

    Prob: List out the employees who are working in department 20

    Sol: SQL > Select * from employee where department_id=20

    Prob: List out the employees who are earning salary between 3000 and 4500

    Sol: SQL > Select * from employee where salary between 3000 and 4500

    Prob: List out the employees who are working in department 10 or 20

    Sol: SQL > Select * from employee where department_id in (20,30)

    Prob: Find out the employees who are not working in department 10 or 30

    Sol: SQL > Select last_name, salary, commission, department_id from employee where 
    department_id not in (10,30)

    Prob: List out the employees whose name starts with “S”

    Sol: SQL > Select * from employee where last_name like ‘S%’

    Prob:List out the employees whose name start with “S” and end with “H”

    Sol: SQL > Select * from employee where last_name like ‘S%H’

    Prob: List out the employees whose name length is 4 and start with “S”

    Sol: SQL > Select * from employee where last_name like ‘S___’

    Prob: List out the employees who are working in department 10 and draw the salaries more than 3500

    Sol:SQL > Select * from employee where department_id=10 and salary>3500

    Prob:list out the employees who are not receiving commission.

    Sol: SQL > Select * from employee where commission is Null

Order By Clause:


    Prob:List out the employee id, last name in ascending order based on the employee id.

    Sol: SQL > Select employee_id, last_name from employee order by employee_id

    Prob:List out the employee id, name in descending order based on salary column

    Sol: SQL > Select employee_id, last_name, salary from employee order by salary desc

    Prob:list out the employee details according to their last_name in ascending order and   
    salaries in descending order

    Sol: SQL > Select employee_id, last_name, salary from employee order by last_name,
    salary desc

    Prob:list out the employee details according to their last_name in ascending order and 
    then on department_id in descending order.

    Sol: SQL > Select employee_id, last_name, salary from employee order by last_name, 
   department_id desc

    
Group By & Having Clause:

   Prob: How many employees who are working in different departments wise in the 
   organization

   Sol:  SQL > Select department_id, count(*), from employee group by department_id

   Prob: List out the department wise maximum salary, minimum salary, average salary of 
   the employees

   Sol:  SQL > Select department_id, count(*), max(salary), min(salary), avg(salary) from 
   employee group by department_id

   Prob: List out the job wise maximum salary, minimum salary, average salaries of the 
   employees.

   Sol: SQL > Select job_id, count(*), max(salary), min(salary), avg(salary) from 
   employee group by job_id

   Prob: List out the no.of employees joined in every month in ascending order.

   Sol: SQL > Select to_char(hire_date,’month’)month, count(*) from employee group by 
   to_char(hire_date,’month’) order by month

   Prob: List out the no.of employees for each month and year, in the ascending order 
   based on the year, month.

   Sol: SQL > Select to_char(hire_date,’yyyy’) Year, to_char(hire_date,’mon’) Month,
   count(*) “No. of employees” from employee group by to_char(hire_date,’yyyy’),
   o_char(hire_date,’mon’)

   Prob: List out the department id having atleast four employees.

   Sol: SQL > Select department_id, count(*) from employee group by department_id having count(*)>=4

   Prob: How many employees in January month.

  Sol : SQL > Select to_char(hire_date,’mon’) month, count(*) from employee group by 
  to_char(hire_date,’mon’) having to_char(hire_date,’mon’)=’jan’

   Prob: How many employees who are joined in January or September month.

  Sol: SQL > Select to_char(hire_date,’mon’) month, count(*) from employee group by 
   to_char(hire_date,’mon’) having to_char(hire_date,’mon’) in (‘jan’,’sep’)

  Prob: How many employees who are joined in 1985.

  Sol : SQL > Select to_char(hire_date,’yyyy’) Year, count(*) from employee group by
  to_char(hire_date,’yyyy’) having to_char(hire_date,’yyyy’)=1985

  Prob: How many employees joined each month in 1985.

  Sol: SQL > Select to_char(hire_date,’yyyy’)Year, to_char(hire_date,’mon’) Month, count(*) “No.  of employees” from employee where to_char(hire_date,’yyyy’)=1985 group by  to_char(hire_date,’yyyy’),to_char(hire_date,’mon’)

  Prob:  How many employees who are joined in March 1985.

  Sol: SQL > Select to_char(hire_date,’yyyy’)Year, to_char(hire_date,’mon’) Month,
  count(*) “No. of employees” from employee where to_char(hire_date,’yyyy’)=1985 and
  to_char(hire_date,’mon’)=’mar’ group by  to_char(hire_date,’yyyy’),
  to_char(hire_date,’mon’)

  Prob: Which is the department id, having greater than or equal to 3 employees joined in
   April 1985.

  Sol: SQL > Select department_id, count(*) “No. of employees” from employee where 
  to_char(hire_date,’yyyy’)=1985 and to_char(hire_date,’mon’)=’apr’ group by
  to_char(hire_date,’yyyy’), to_char(hire_date,’mon’), department_id having
  count(*)>=3

Sub-Queries

   Prob: Display the employee who got the maximum salary.

   Sol: SQL > Select * from employee where salary=(select max(salary) from employee)

   Prob: Display the employees who are working in Sales department

  Sol : SQL > Select * from employee where department_id IN (select department_id from
  department where name=’SALES’)

  Prob:Display the employees who are working as “Clerk”.

  Sol: SQL > Select * from employee where job_id in (select job_id from job where
  function=’CLERK’

  Prob: Display the employees who are working in “New York

  Sol: SQL > Select * from employee where department_id=(select department_id from
  department where location_id=(select location_id from location where regional_group=
  ’New York’))    

   Prob: Find out no.of employees working in “Sales” department.

   Sol: SQL > Select * from employee where department_id=(select department_id from
   department where name=’SALES’ group by department_id)

   Prob: Update the employees salaries, who are working as Clerk on the basis of 10%.

   Sol: SQL > Update employee set salary=salary*10/100 wehre job_id=(select job_id from job where function=’CLERK’)

   Prob: Delete the employees who are working in accounting department.

   Sol : SQL > delete from employee where department_id=(select department_id from department    where name=’ACCOUNTING’)

   Prob:  Display the second highest salary drawing employee details.

   Sol:  SQL > Select * from employee where salary=(select max(salary) from employee where salary <(select max(salary) from employee))

   Prob: Display the Nth highest salary drawing employee details.

   Sol: SQL > Select distinct e.salary from employee where & no-1=(select count(distinct salary)  from employee where sal>e.salary)

Sub-Query operators: (ALL,ANY,SOME,EXISTS)

   Prob: List out the employees who earn more than every employee in department 30.

   Sol: SQL > Select * from employee where salary > all (Select salary from employee where department_id=30)

   Prob: List out the employees who earn more than the lowest salary in department 30.

   Sol: SQL > Select * from employee where salary > any (Select salary from employee where department_id=30)

   Prob: Find out whose department has not employees.

   Sol: SQL > Select employee_id, last_name, department_id from employee e where not exists (select department_id from department d where d.department_id=e.department_id)

   Prob: Find out which department does not have any employees.

   Sol: SQL > Select name from department d where not exists (select last_name from employee e where d.department_id=e.department_id)


Co-Related Sub Queries:

   Prob: find out the employee who can earn greater than the average salary for their department.

  Sol: SQL > Select employee_id, last_name, salary, department_id from employee e where   salary > (select avg(salary) from employee where department_id=e.department_id)

Joins

Simple join

   Prob: List our employees with their department names

   Sol:  SQL > Select employee_id, last_name, name from employee e, department d where  e.department_id=d.department_id

   Prob: Display employees with their designations (jobs)

   Sol: SQL > Select employee_id, last_name, function from employee e, job j where 
   e.job_id=j.job_id

   Prob: Display the employees with their department name and regional groups

   Sol: SQL > Select employee_id, last_name, name, regional_group from employee e, department d, location l where e.department_id=d.department_id and d.location_id=l.location_id

   Prob: How many employees who are working in different departments and display with
   department name. 

   Sol: SQL > Select name, count(*) from employee e, department d where 
   d.department_id=e.department_id group by name

   Prob: How many employees who are working in sales department.

   Sol:  SQL > Select name, count(*) from employee e, department d where
   d.department_id=e.department_id group by name having name=’SALES’

   Prob: which is the department having greater than or equal to 5 employees and display the department name in ascending order.

   Sol:  SQL > Select name, count(*) from employee e, department d where 
   d.department_id=e.department_id group by name having count (*)>=5 order by name


   Prob: How many jobs in the organization with designations.

   Sol:  SQL > Select function, count(*) from employee e, job j where j.job_id=e.job_id group by    function

   Prob: How many employees working in “New York”.

   Sol: SQL > Select regional_group, count(*) from employee e, department d, location l where  e.department_id=d.department_id and d.location_id=l.location_id and regional_group=’NEW YORK’ group by regional_group

Non – Equi Join:

    Prob: Display employee details with salary grades.

   Sol: SQL > Select employee_id, last_name, grade_id from employee e, salary_grade s where salary between lower_bound and upper_bound order by last_name

   Prob: List out the no. of employees on grade wise.

   Sol : SQL > Select grade_id, count(*) from employee e, salary_grade s where salary between  lower_bound and upper_bound group by grade_id order by grade_id desc

   Prob: Display the employee salary grades and no of employees between 2000 and 5000 of salary.

   Sol: SQL > Select grade_id, count(*) from employee e, salary_grade s where salary between lower_bound and upper_bound and lower_bound>=2000 and lower_bound<=5000 group by grade_id order by grade_id desc

Self Join:

    Prob: Display the employee details with their manager names.

   Sol: SQL > Select e.last_name emp_name, m.last_name, mgr_name from employee e, employee m where e.manager_id=m.employee_id

   Prob: Display the employee details who earn more than their managers salaries.

   Sol: SQL > Select e.last_name emp_name, e.salary emp_salary, m.last_name, mgr_name,  m.salary mgr_salary from employee e, employee m where e.manager_id=m.employee_id and m.salary

   Prob: Show the no. of employees working under every manager.

   Sol: SQL > Select m.manager_id, count(*) from employee e, employee m where 
   e.employee_id=m.manager_id group by m.manager_id

Outer Join:

   Prob: Display employee details with all departments.

  Sol: SQL > Select last_name, d.department_id, d.name from employee e, department d where e.department_id(+)=d.department_id

  Prob: Display all employees in sales or operation departments.

  Sol : SQL > Select last_name, d.department_id, d.name from employee e, department d where e.department_id(+)=d.department_id and d.department_idin (select department_id from department where name IN (‘SALES’,’OPERATIONS’))

Set Operators:

Prob: List out the distinct jobs in Sales and Accounting Departments.

Sol : SQL > Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’SALES’)) union Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’ACCOUNTING’))

Prob: List out the ALL jobs in Sales and Accounting Departments.

Sol:  SQL > Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’SALES’)) union all Select  function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’ACCOUNTING’))

Prob: List out the common jobs in research and accounting departments in ascending orders.

Sol: SQL > Select function from job where job_id in (Select job_id from employee where department_id=(select department_id from department where name=’RESEARCH’)) intersect  Select function from job where job_id in (Select job_id from employee where department_id= (select department_id from department where name=’ACCOUNTING’)) order by function