Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is it possible to display other column names from two table to one table by using join clause by using foreign key

Good day Sir/Ma’am, I need help regarding on Join clause is it possible to use join clause in multiple column names from other table with foreign key?
Problem: I have table named
Table 1: ‘biditem’
COL.1: biditemid(pk)
COL.2: user_id(fk)
COL.3: product_id(fk)
COL.4: bidamountprice (decimal)
COL.5: bidtime (datetime)

Table 2: ‘user’
COL.1: user_id(pk)
COL.2: user_firstname (varchar)
COL.3: user_middlename (varchar)
COL.4: user_lastname (varchar)

Table 3: ‘product’
COL.1: product_id(pk)
COL.2: product_name varchar(25)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want to display from the biditem look like this in php
enter image description here

>Solution :

You can also write your query like

select 
   b.biditemid, 
   concat(u.user_firstname,' ',u.user_middle,' ',u.user_lastname) as name, 
   p.product_name,
   b.bidamountprice, 
   b.bidtime
from 
   bitem b,
   user u,
   product p
where
   b.user_id=u.user_id
   and b.product_id=p.product_id
  • name your table with alias short form
  • always remember for joining if you have 3 tables then 3-1 will be your minimum where clauses to make proper join with your all tables
  • likewise you had 3 tables so the minimum number or where clause use was 2 in your above code.

You can use that standard and you can use left inner, outer join too whatever you are comfort in. Both standards can be use in oracle sqlplus, mySql, postgreSql

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading