80532

Join Multiple tables in oracle sql

Question:

im new to SQL and want to know how to replace the below code with SQL joins.

I want to list all information based on p_id ='123'.

select p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact from product p, category c, seller s, buyer b where p.p_id="123" and c.p_id="123" and s.p_id="123" and b.p_id="123";

Tables used

<strong>Product Table</strong>

p_id p_name

<strong>Category Table</strong>

p_id c_id c_name

<strong>Seller Table</strong>

p_id s_id s_name s_contact

<strong>Buyer Table</strong>

p_id b_id b_name b_contact

Thanks

Answer1:

This is the query using join:

select p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact from product p join buyer b on p.p_id = b.p_id and <second condition> join category c on p.p_id = c.p_id join seller s on c.p_id = s.p_id where p.p_id="123" ;

Answer2:

Try joining all the table with your criteria as below:

SELECT p.p_name,c.c_name,s.s_name,s.s_contact,b.b_name,b.b_contact FROM product p INNER JOIN category c ON p.p_id = c.p_id INNER JOIN seller s ON p.p_id = s.p_id INNER JOIN buyer b ON p.p_id = b.p_id WHERE p.p_id='123';

Recommend

  • Javascript form won't submit
  • SQL query to relate 2 tables
  • Python click button with requests
  • How to enable Mobile PayPal Payments Standard on sandbox?
  • Hibernate Creating Unwanted Mapping Tables
  • PayPal Account Balance -0 USD
  • Organize database & multichoice columns by cronjob
  • Best match using MySQL and PHP
  • How to implement 'category' based newsletter
  • select query and count based on condition
  • .htaccess rewriteRule conflict
  • Display name for nested complex type
  • How to validate a url with lots of querystrings
  • How instagram or direct not change shape in icon launcher to circle in android oreo
  • APK 0 (zero) Device compatibility
  • MySQL table structure question
  • Wordpress Create Category AJAX Response
  • Mule ESB connecting to RabbitMQ
  • MapView: Could not find class A referenced from method B
  • Update transparancy of jFreeChart in real time with JSlider
  • Categories and SubCategories
  • AngularJS- How to pass data from one controller to another on ng-click()?
  • Custom font for MKAnnotationView Callout
  • Java thread for JDBC
  • PHPUnit: Expected status code 200 but received 419 with Laravel
  • WooCommerce - related products by tags and categories
  • How to resolve “ Multiplicity is not valid in Role” error?
  • missing parameter name at index 0 {}
  • Scrolling News Ticker Jquery - Issues
  • Using extern @class in order to add a category?
  • “A GKScore must specify a leaderboard.”
  • Magento get URL before current
  • Azure table store snapshot/backup capability
  • Bigquery event streaming and table creation
  • MongoDB in PHP using aggregate to group by _id is null not working
  • Linq Objects Group By & Sum
  • Large data - storage and query
  • XCode can't find symbols for a specific iOS library/framework project
  • KeystoneJS: Relationships in Admin UI not updating
  • Getting Messege Twice Using IMvxMessenger