select where field equals one of multiple values - sql

I want rows but in WHERE I have different values. How can I get these rows? Let's say I want to check names of people with different cnic values?
select name from table where cnic='123','234','134';
It gives me an error. How can I do this?

use mysql In operator for checkinng multiple values.
select name from table `where cnic IN ('123','234','134');

Please use the In operator for this
select name from table where cnic in ('123','234','134')

Related

Teradata Character Column with non alphabet values

I have a name column in Teradata that has customer full name all in one column. There are some names with -,_,.,/,#,! in between the name characters. I want to be able to pull records where there are names with these conditions. Is there a better option to pull records with the scenario below?
Currently, I am writing query like this
SELECT NAME FROM TABLESOURCE WHERE NAME LIKE ANY('%-%','%.%','%#%','%~%','%!%')
Thanks in advance.
I haven't tested this but I think you could test for equality when those characters are removed from the name using otranslate
select name
from tablesource
where name <> otranslate(name,'-.#~!','')

SQL: What does NULL as ColumnName imply

I understand that AS is used to create an alias. Therefore, it makes sense to have one long name aliased as a shorter one. However, I am seeing a SQL query NULL as ColumnName
What does this imply?
SELECT *, NULL as aColumn
Aliasing can be used in a number of ways, not just to shorten a long column name.
In this case, your example means you're returning a column that always contains NULL, and it's alias/column name is aColumn.
Aliasing can also be used when you're using computed values, such as Column1 + Column2 AS Column3.
When unioning or joining datasets using a 'Null AS [ColumnA] is a quick way to make sure create a complete dataset that can then be updated later and a new column does not need to be created in any of the source tables.
In the statement result we have a column that has all NULL values. We can refer to that column using alias.
In your case the query selects all records from table, and each result record has additional column containing only NULL values. If we want to refer to this result set and to additional column in other place in the future, we should use alias.
It means that "aColumn" has only Null values. This column could be updated with actual values later but it's an empty one when selected.
---I'm not sure if you know about SSIS, but this mechanism is useful with SSIS to add variable value to the "empty" column.
When using SELECT you can pass a value to the column directly.
So something like :
SELECT ID, Name, 'None' AS Hobbies, 0 AS NumberOfPets, NULL AS Picture, '' AS Adress
Is valid.
It can be used to format nicely a query output when using UNION/UNION ALL.
Query result can have a new column that has all NULL values. In SQL Server we can do it like this
SELECT *, CAST(NULL AS <data-type>) AS as aColumn
e.g.
SELECT *, CAST(NULL AS BIGINT) AS as aColumn
How about without using the the as
SELECT ID
, Name
, 'None' AS Hobbies
, 0 AS NumberOfPets
, NULL Picture
Usually adding NULL as [Column] name at the end of a select all is used when inserting into another table a calculated column based on the table you have just selected.
UPDATE #TempTable SET aColumn = Column1 + Column2 WHERE ...
Then exporting or saving the results to another table.

how to join on varchar(32) and binary(16) columns in sybase?

I want to join two tables on a UUID. table A's UUID is represented as varchar(32). table B's UUID is represented as binary(16).
what's the best way to join a varchar to a binary column?
I've tried using some sybase functions for this, but I'm getting different results and unsure of why:
select hextobigint('0x000036ca4c4c11d88b8dcd1344cdb512')
3948051912944290701
select convert(bigint,0x000036ca4c4c11d88b8dcd1344cdb512)
-2877434794219274240
what am I missing about convert and hextobigint? I must be misundstanding at least one of these functions. thanks for your help!
got it eventually with the help of some colleagues:
select strtobin(convert(char(32), '000036ca4c4c11d88b8dcd1344cdb512'))
The problem is on the select convert(bigint,0x000036ca4c4c11d88b8dcd1344cdb512).
If you remove the first zeros it'll give you the same result:
select hextobigint('0x000036ca4c4c11d88b8dcd1344cdb512')
and
select convert(bigint,0x36ca4c4c11d88b8dcd1344cdb512)

Get alias name dynamically in Postgresql

I have one table named tblalias.which is having two columns cid, description
cid description
1 Employee
2 Join Date
3 Retire Date
Like this three record is present
Now I have another table tblemployee. I want to write a query for tblemployee to get record but alias name for that query I want should come from tblalias
select nama as Employee,
joindate as "Join Date",
retiredate as "Retire Date"
from tblemployee
If I change value is tblalias table to my select query should return new value as alias is it possible if yes how please help me
The only way to do this is with dynamic SQL. First fetch the alias names then build the final SQL and execute it.
There is no way doing this with a single "hardcoded" statement.
If you want spaces in names you should quote them. (spaces in names is generally a bad Idea, but that's another matter)

Does the result of SELECT MAX([ColumnName]) have a column name?

Does the result of SELECT MAX([ColumnName]) have a column name? I know the result is a view of only one record and I'd thought this view has the original column name as the result column name?
It does not but you can give it one
SELECT MAX([ColumnName]) AS MaxName
If you think about it you will see why your assumption is wrong. What if the code was like this:
SELECT MAX([ColumnName]), MIN([ColumnName])
Which of the two will take the name of the column?
By default no, there is no particular column name. If you specify an alias it will have.
SELECT MAX([ColumnName]) as [max_value_column_name]