|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
I have 3 identical tables. Let us say that it just contains 2 columns company_code and price. Is it possible to get the first occurrence of the price for example company_code='MSFT' from these tables.
The catch is the query should display the first occurence only. If the table 1 contain the price for MSFT then the output should only display the value from table 1 and ignore table 2 and 3, else it should check in table 2 and ignore table 3 or else it should display from table 3. |
|
#2
|
|||
|
|||
|
I guess,
SELECT distinct company_code, price FROM table1 a, table2 b, table3 c WHERE a.comapny_code = 'MSFT' OR b.company_code = 'MSFT' OR c.comapny_code = 'MSFT' / |
|
#3
|
|||
|
|||
|
the best way to do so is using union set operator in your query as given below:
SELECT company_code,price from tabe1 WHERE company_code ='MSTF' UNION SELECT company_code,price from tabe2 WHERE company_code ='MSTF' UNION SELECT company_code,price from tabe3 WHERE company_code ='MSTF' UNION set operator not only merge the data set of query based on different table but also eliminate the duplicate records. If you want to see the duplicate record as well then use UNION ALL instead of using UNION. |
![]() |
| Viewing: Dev Shed Forums > Databases > Oracle Development > Is this possible with a Single SQL Query? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|