SQL Select all rows with specific value [duplicate] - sql

This question already has an answer here:
How can I select a value from one row in SQL Server?
(1 answer)
Closed 6 years ago.
Trying to select all rows with the value 33487MO in the column ORMSTRID
This is my current query -
SELECT * from MyTable
Where ORMSTRID = "33487MO"
But it gives me an error that is saying Invalid column name '33487MO'
SELECT * from MyTable
shows me all of the rows and columns from the table, and ORMSTRID is definitely the column name.

You should use single quote with string data
According your example your query should be:
select * from mytable
where ORMSTRID like '33487MO'

Related

Dynamic oracle sql query based on start and end date [duplicate]

This question already has answers here:
Pivot in Oracle 11g
(2 answers)
Closed 2 years ago.
My table:
Based on Start and End date, I need to get output something like this:
Assume start date as 1-sep-2020 and end date as 09-sep-2020 (provided dynamically).
Based on above dates, date should be column name and id should be data under respective column.
If id is not present on respective date, in input table it should be null.
I'm not able to figure out query for this. Please, anyone suggest me in writing the query for above.
Thanks in Advance.
You can try this:
SELECT * FROM
(
SELECT name, dat, id
FROM tbl
)
PIVOT
(
max(id)
FOR dat IN ('01-Sep-2020', '02-Sep-2020', '03-Sep-2020', '04-Sep-2020', '05-Sep-2020', '06-Sep-2020', '07-Sep-2020')
)
ORDER BY name;
https://dbfiddle.uk/?rdbms=oracle_18&fiddle=63413c3d5ce0e3a67e9c18d0fe39b21f

SQL values from one table into multiple columns [duplicate]

This question already has answers here:
Convert Rows to columns using 'Pivot' in SQL Server
(9 answers)
Closed 2 years ago.
I have made a code as followed:
select
PMGCONTACTPERSON.RECID AS 'Recid'
,PMGCONTACTPERSON.ROLEID AS 'Rol'
,DIRPARTYTABLE.NAME
from PMGCONTACTPERSON
left join DIRPARTYTABLE
ON DIRPARTYTABLE.PARTYID = PMGCONTACTPERSON.PARTYID
What I would like te get is columns named after the rolid and values filled with the names.
Any ideas?
I think you are looking to Pivot the table i.e. rows to columns. You can use PIVOT clause in SQL SERVER.
SELECT * FROM (
SELECT ROLE_NAME, NAME FROM TEST_NAME) T
PIVOT(MAX(NAME) FOR ROLE_NAME IN ([MANAGER], [ENGINEER])) AS PIVOT_TABLE;

When I try to select 1 row it selecting both rows into my database? [duplicate]

This question already has answers here:
PHP PDO returning single row
(7 answers)
Closed 4 years ago.
select * from addcuust order by customer asc
This is my query. When I run this query both rows selecting what should I do?
I just want 1 row at once.
select * from addcuust order by customer asc limit 1

Want to add multiple values in "NOT Like" in where condition in sql [duplicate]

This question already has answers here:
SQL Query with NOT LIKE IN
(9 answers)
Closed 4 years ago.
I have a query in which I want to check for multiple values which should not be in where clause. I want to exclude those records which have those values
Select * from Order where order_number NOT LIKE ('%asd%','%ass%','%asdd%')
I guess you'll have to go with a typical AND:
Select * from Order where
order_number NOT LIKE '%asd%'
AND order_number NOT LIKE '%ass%'
AND order_number NOT LIKE '%asdd%'

PostgreSQL ORDER BY clause on numerical portion of text column [duplicate]

This question already has answers here:
SQL multiple column ordering
(9 answers)
PostgreSQL ORDER BY issue - natural sort
(9 answers)
Closed 7 years ago.
I have a table that has a column as primary key and the values are
G1,G2,G3,...Gn
I would like to order the data but the problem is when I use the ORDER BY clause it displays data as:
G1,G10,G11... G2,G20,G21, ... G3,G30,G31....
The query I use is:
select * from myTable order by id asc;
Your id column is obviously of some text data type so the ordering is alphabetical, not by the number. To get it to work, strip the 'G' from the id column when ordering:
SELECT * FROM mytable
ORDER BY right(id, -1)::integer;