I would like to do something like Is it possible to somehow do the “AS my_select” part (i.e. assign an alias to a SELECT statement)? (Note: This is a theoretical question. I realize that I can do it without assign an alias to a SELECT statement, but I would like to know whether I can do it with that.) Answer
Tag: select
How to use SELECT DISTINCT with RANDOM() function in PostgreSQL?
I am trying to run a SQL query to get four random items. As the table product_filter has more than one touple in product i have to use DISTINCT in SELECT, so i get this error: for SELECT DISTINCT, …
JOIN two SELECT statement results
Is it possible to join the results of 2 sql SELECT statements in one statement? I have a database of tasks where each record is a separate task, with deadlines (and a PALT, which is just an INT of days from start to deadline. Age is also an INT number of days.) I want to have a table which has
How can I select from list of values in Oracle
I am referring to this stackoverflow answer: How can I select from list of values in SQL Server How could something similar be done in Oracle? I’ve seen the other answers on this page that use UNION …
Return all duplicate rows
I’ve written this code to find duplicates and it works fine: The problem is, it’s returning just one of the duplicate rows. Is it possible to return all the duplicate rows? I’m guessing it may have something to do with the ‘GROUP BY’ but I’m not sure how to change it. I don’t want to delete the values, just return
SQL WHERE ID IN (id1, id2, …, idn)
I need to write a query to retrieve a big list of ids. We do support many backends (MySQL, Firebird, SQLServer, Oracle, PostgreSQL …) so I need to write a standard SQL. The size of the id set could be big, the query would be generated programmatically. So, what is the best approach? 1) Writing a query using IN My
Select 2 columns in one and combine them
Is it possible to select 2 columns in just one and combine them? Example: select something + somethingElse as onlyOneColumn from someTable Answer Yes, just like you did: If you queried the database, you would have gotten the right answer. What happens is you ask for an expression. A very simple expression is just a column name, a more complicated
How to select only the first rows for each unique value of a column?
Let’s say I have a table of customer addresses: In the table, one customer like John Smith can have multiple addresses. I need the SELECT query for this table to return only first row found where there are duplicates in ‘CName’. For this table it should return all rows except the 3rd (or 1st – any of those two addresses
Mysql SELECT CASE WHEN something then return field
I have two field nnmu and nnmi , and reverse, At first everything looks good, but somehow it mix up values, it work when nnmi and nnmu both are equal to 0, but when either value is 1 it returns nonsense. Any help? Answer You are mixing the 2 different CASE syntaxes inappropriately. Use this style (Searched) Or this style
How can SELECT COUNT(*) different from count of all records in the table?
So I have a table: SELECT COUNT(*) returns a different value than SELECT DISTINCT COUNT(*). How can this be possible? I also tried which returned the same count as the distinct query. I can’t see how with a primary key and all fields being NOT NULL, there can be a different total count than the count of unique records. BTW,