Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 months ago.
Improve this question
can anyone tell me why I can not run this code in SQL Management studio?
Thanks in advance.
SELECT * FROM TabKontaktJednani
where
TabKontaktJednani.Typ IN (
CASE 'ERP'--(SELECT ALIAS FROM TabCisZam where LoginId = SUSER_NAME())
WHEN 'ERP'
THEN ('HeO','OST')
WHEN 'TO'
THEN ('SW','OST')
END)
The reason you can't run that code is that CASE expressions can only return one scalar value, not a list of values.
Your CASE expression returns a tuple. That is not allowed in SQL. But as MySQL supports a boolean data type, a CASE expression may result in a boolean:
SELECT *
FROM tabkontaktjednani
WHERE
CASE (SELECT alias FROM tabciszam WHERE loginid = suser_name())
WHEN 'ERP' THEN typ IN ('HeO', 'OST')
WHEN 'TO' THEN typ IN ('SW', 'OST')
END;
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
i have my json like this
my column name is data
[
{
"DetailMaster":{
"DetailsID":"FD001",
"Number":"9W82Q",
"RegNumber":"SF AAV",
"Hours":"4000"
},
"DetailChild":[
{
"subDetailsID":"FD001_Sub01",
"DetailsID":"FD001",
"model":"B737"
}
]
}
]
i just want to get the column data by providing the Number and RegNumber in json. how can i do that
It can be achieved in two methods.
1)using JSON_EXTRACT
mysql> SELECT c, JSON_EXTRACT(c, "$.id"), g
> FROM jemp
> WHERE JSON_EXTRACT(c, "$.id") > 1
> ORDER BY JSON_EXTRACT(c, "$.name");
2)Using column->>path
The -> operator serves as an alias for the JSON_EXTRACT() function when used with two arguments, a column identifier on the left and a JSON path on the right that is evaluated against the JSON document (the column value). You can use such expressions in place of column identifiers wherever they occur in SQL statements.
mysql> SELECT c, c->"$.id", g
> FROM jemp
> WHERE c->"$.id" > 1
> ORDER BY c->"$.name";
where c is the column of a JSON.
for more reference kindly go through the MySQL official site.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to find the Age based off date of birth. I keep getting a syntax error in the subquery.
I'm getting on error on the - CUST_DOB /365,0) As Age from customer; to use the correct syntax. Error Code 1064
SELECT CUST_LNAME, CUST_FNAME, ROUND((NOW() – CUST_DOB)/365,0) AS AGE
FROM CUSTOMER;
There is a problem with the minus (-) sign. please use it like
SELECT CUST_LNAME, CUST_FNAME, ROUND((NOW() - CUST_DOB)/365,0) AS AGE
FROM CUSTOMER;
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I want to retrieve all the properties in the range 2200000(min_price) to 2700000(max_price)
The query should look like
SELECT *
FROM properties
WHERE ( ((raw_min >= '{$min_price}')
OR (raw_min <= '{$max_price}'))
AND ((raw_max >= '{$min_price}')
OR (raw_max <= '{$max_price}')))
AND (..)
query should satisfy the below 6 conditions
raw_min - raw_max
(1) 1000000-2000000 (false)
(2) 1500000- 2400000 (true)
(3) 2300000-2600000 (true)
(4) 2500000-3000000 (true)
(5) 3200000-5000000 (false)
(6) 2000000-3000000 (true)
Please try this query:-
SELECT *
FROM properties
WHERE (raw_min between 2200000 AND 2700000)
OR (raw_max between between 2200000 AND 2700000)
OR (raw_min <= 2200000 && raw_max >= 2700000)
Please check I have updated the query.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my database table have this value,i have to check this email value 'abc#gmail.com' is exist in the database or not.
abc#gmail.com
edf#dfg.com
xyz#abcinfo.com
12345#fdfg.com
If 'abc#gmail.com' value is exist in the database table, output is true else false, so how to write the query for this to achieve?
thanks
Kumar
You can do something as simple as
select CASE WHEN count(1) > 0 THEN 'true' ELSE 'false' END from table where email = 'abc#gmail.com'
But you should give some more information for a beater answer.
you can write query like
SELECT IF(COUNT(*) >0, TRUE,FALSE)as response FROM <tablename> WHERE emailid='edf#dfg.com';
select exists(
SELECT 1 FROM <tableName> WHERE email LIKE 'abc#gmail.com'
)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to fetch mysql data having round brackets e.g. ABCD(XYZ). When I run query
"SELECT * FROM tablename WHERE Column = 'ABCD(XYZ)'"
it returns an empty result. Please suggest a way. Thanks in advance!
this should work:
INSERT INTO `tablename` (`Column`) VALUES ('ABCD(XYZ)');
SELECT * FROM `tablename` WHERE `Column` = 'ABCD(XYZ)'";
Maybe 'ABCD(XYZ)' is not exactly the value of your data (for example if you inserted some whitespaces before or after it.)
You can try it with a like to find that out:
SELECT * FROM `tablename` WHERE `Column` LIKE '%ABCD(XYZ)%'";
Another possibility is that your value has been converted with htmlentities and you saved something like this:
'ABCD&40;XYZ&41;'
&40; Left parenthesis
&41; Right parenthesis