SQL Distinct limitation - sql

i Have a table that contain coordinates info...like this:
Li_from
----------
36.2090536962569;37.1511090538763
36.2130356969589;37.1443713448309
36.2130876347598;37.1508944771551
36.2093999652314;37.1442425987982
36.2130356969589;37.1443713448309
36.2130356969589;37.1443713448309
and when i want to select distinct values from the column above like this:
SELECT DISTINCT Li_from from table.
the result is the same as above although the last two values are identical ..
so is there limitation for the distinct keyword , and how can i select distinct values??

Are you sure the last two columns are identical? Have you tried SELECT DISTINCT LTRIM(RTRIM(Li_from)) from table?
This will remove leading and trailing space characters.

Related

DISTINCT in SQL Redshift

What does the query below give exactly? I have tried to play around with it but don't understand the results generated.
SELECT DISTINCT metric, value
FROM
Table X
If I had just "SELECT DISTINCT metric FROM table X", I understand that it would just return all distinct values in the column metric but what is it doing when you add an extra column to the end (like the above case where we have the column "value")?
When you use distinct with multiple columns in the select clause it acts on all the columns to give you unique combinations of those column values.
The addition of a column meaning more than one column in select with a distinct would treat both the columns together as unique not one column only as if suppose one column has more duplicates than the other then if distinct gives unique for one column and not the other then it would led to inconsistency
The metric and value column will act as a combination here. If the metric=table_name has two tables x, y with different owner then the distinct result will be
table_name - x
table_name - y

How to concat, find duplicates and display result after joining mulitple tables(9-10)

I want to concat one column each from multiple tables , after concatenation find if there are duplicates in the concatenation , display duplicates with a ID column from one of first tables.
I am able to do this but query which I have done looks very long and is bad from a performance perspective.
Here is the logic which is working -
SELECT ID , concatcolumn where concat column in (
(select concat
join all tables
group by concatcolumn
having count(id)>1) a
JOIN
(select id, concat
join all tables) b
on a.concatcolumn = b.concatcolumn )
This gives me what I want but I am no happy with it as
concatcolumn is a concatenation of 10 columns atleast , and wherever i have mentioned it will be replaced by that code.
Is there any other easier way ?

How to order the SQL result on all columns without specifying them individually?

Suppose my table tabname has 5 columns.
I want to do this :
select * from tabname order by col1,col2,col3,col4,col5
Instead of that, is there a way similar to this :
select * from tabname order by 'AllColumns'
With the above line, I should be able to order the results on all the columns without specifying them individually. Using the Informix Database?
You can't do it. One way is to use select field number, but this works if columns count in the select statement is fixed (or not less than numbers you use in the ORDER BY).
For example if you have always 5 columns (or more) in the select list you can run following query:
select * from tabname order by 1,2,3,4,5
In this example it means that 1 - is a first column in the select list, 2 is the second ,....

Why does the number of rows increase in a SELECT statement with INNER JOIN when a second column is selected?

I am writing some queries with self-joins in SQL Server. When I have only one column in the SELECT clause, the query returns a certain number of rows. When I add another column, from the second instance of the table, to the SELECT clause, the results increase by 1000 rows!
How is this possible?
Thanks.
EDIT:
I have a subquery in the FROM clause, which is also a self-join on the same table.
How is this possible?
the only thing I can think of is that you have SELECT DISTINCT and the additional column makes some results distinct that weren't before the additional column.
For example I would expect the second result to have many more rows
SELECT DISTINCT First_name From Table
vs
SELECT DISTINCT First_name, Last_name From Table
But if we had the actual SQL then something else might come to mind

sqlite get records with same column value

I have a SQLite DB that has people LastName, FirstName, Department and I need to make a query that shows me any people with the same First & Last Names. I've found the following statement that supposedly does what I want for a single field, however it doesn't seem to work for me when I try to use it to pull all records with just the last name being the same. How can I do this?
Select myField From myTable Group by myField Where count(myField)>1
try:
Select
firstname,LastName,Count(*)
From myTable
Group by firstname,LastName
HAVING Count(*)>1
GROUP BY combines rows where the named values are the same.
HAVING removes groups that do not meet the condition.
The above query will list the first and last names, along with a count of duplicates for all first/last names that actually have duplicates.
Firstly, you need to use HAVING, not WHERE to qualify the GROUPed BY result:
SELECT myField FROM myTable GROUP BY myField HAVING COUNT(myField) > 1
Secondly, you can extend this to multiple columns like this:
SELECT MyCol1, MyCol2 FROM MyTable
GROUP BY MyCol1, MyCol2
HAVING COUNT(*) > 1