Skip to content

Tag: sql

Using the Like operator with two fields

How do I use the Like operator to join two unidentical tables as below? My main problem is on how to compare the PO filed on tbl2 to the EditNo on tbl1 field. Please see sample tables and expected results below: tbl1: tbl2: Expected: Query: SELECT * FROM tbl2 INNER JOIN tbl1 ON tbl2.PONo LIKE EditNo.PO; Answe…

Order by a subtraction expression sql

I would like to perform an ORDER BY in sql that sorts the returned rows by their distance from my integer of interest. The expression would be ORDER BY (constant – ColumnName) ASC specifically, something like ORDER BY (10 – Distance) ASC. When I tried running this expression the distances were jus…

Syntax error for nested condtionals in SQL

I’m pretty new to redshift and I’ve been trying to to do a nested case when condition here, yet I get a syntax error ERROR: syntax error at or near “)” in this line of SQL: I’m not sure what’s wrong, since I’m familiar with Python and I’m pretty sure this is how…

Joining two tables to keep selected values and nulls

I have got two tables that I need to join. The second table is used to filter the records from the first table. table1.parameter table2.parameter; table2.parameter_group The result should include all records from table1 for a certain parameter_group but also records where the parameter is null. What I have is…

there is a way to order empty element like null element?

I need to order a column and there are a lot of elements null or empty.The problem is null element are ordered differente from null element The result about is that employees with name==null are the first position, after there are the elements with name!=null (are a real name) and at the end there are the ele…