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

SQL join query and with emtpy fields or with fields containing a text

im trying to build a select query with fields from two tables and also other fields which do not exist in my DB. E.g. emtpy fields or fields with particular text like ‘not available’

for example my query looks like this:

select 
Product.id, 
Product.component_number,
Product_discount.price,
from Product
left join Product_discount ON Product_discount.id = Product.id
where 
Product.deleted = 0 

Now in the same query I want to add fields that do not exist like:

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

Codenumber >> should always be emtpy

Factor >> should always contain the text ‘Yes’ for every row

idea is to build a query that is identical to an import file

Thanks…

>Solution :

You can try this:

select 
       Product.id, 
       Product.component_number,
       Product_discount.price,
       ''    as Codenumber,
       'Yes' as Factor 
  from Product
  left join Product_discount ON Product_discount.id = Product.id
 where Product.deleted = 0;

Thank you

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