Return value from SQL commands
I am currently using the SQL command
Select * from where name='john'
Is it possible to return 20 regardless of the request like
Select * from where name='john' or return = 20
+3
gaurav singh
source
to share
3 answers
EDIT If you have an oracle database you can do something like this:
SELECT *
FROM dual
WHERE 1=0
UNION
SELECT '20'
FROM dual;
+1
JJJ
source
to share
check my answer
if exists (Select * from item where ItemName='ABC Daycare1')
begin
Select * from item where ItemName='ABC Daycare1'
end
else
select '20'
+1
Jinto john
source
to share
Try to run this. This should return the top result (which is not 20 due to custom sorting) and then when the name doesn't match the value it returns "Mark" and 20
SQL
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
CREATE TABLE #temp (id int NOT NULL, name varchar(255) NOT NULL)
INSERT INTO #temp (id, name) VALUES (88,'John')
INSERT INTO #temp (id, name) VALUES (20,'Mark')
SELECT TOP 1
*
FROM #temp
WHERE (name = 'Mark' OR name = 'John')
ORDER BY (
CASE
WHEN id = 20 THEN 0 ELSE 1
END) DESC
MySQL - MySQL script
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
CREATE TABLE #temp (id int NOT NULL, name varchar(255) NOT NULL)
INSERT INTO #temp (id, name) VALUES (88,'John')
INSERT INTO #temp (id, name) VALUES (20,'Mark')
SELECT
*
FROM temp
WHERE (name = 'Mark' OR name = 'John')
ORDER BY (
CASE
WHEN id = 20 THEN 0 ELSE 1
END) DESC
LIMIT 1
0
Tom
source
to share