Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting up a default value of a column in select statement

actually i have 2 tables table1 and table2

table1

name
city
addr.

table2

name
city
addr.
ph.no

now ph.no field is an extra field in table 2

so i want to show field ph.no with a default value of 12345 in the output of select query on table1 as i want to append that output into an outfile. help me out ..I am using db2 as400 database

like image 378
abhinav singh Avatar asked Aug 17 '10 18:08

abhinav singh


2 Answers

Yes, you can do this:

SELECT name, city, addr, 12345 AS ph_no
FROM table1
like image 72
Mark Byers Avatar answered Oct 19 '22 14:10

Mark Byers


I know this thread is very old but in case someone needs an answer to Nimmagadda's question, you should be able to accomplish it with something along the lines of:

SELECT name, city, addr, 
CASE name 
  WHEN 'john' THEN 12345 
  WHEN 'peter' THEN 123 
  ELSE 0 /* ???? */ END AS ph_no
FROM table1
like image 3
user9600226 Avatar answered Oct 19 '22 13:10

user9600226