I want to return 1 if some number already exists in table and 0 otherwise. I tried something but it doesn’t work: I want something similar to exists function that already exists in PostgreSQL, but instead of true and false I want 1 or 0. Answer EXISTS yields a boolean result. The simple way to achieve w…
Tag: sql
MySQL category with parent_id – SELF Join
My SQL table called categories has the following structure: I would like to know if it’s possible to JOIN the same table and present the parent_id name. I can do this by PHP code, but I would like, because of performance issues, to retrieve as SQL Query. See example at SQLFiddle I’ve managed to JO…
How to Select Top 100 rows in Oracle?
My requirement is to get each client’s latest order, and then get top 100 records. I wrote one query as below to get latest orders for each client. Internal query works fine. But I don’t know how to get first 100 based on the results. Any ideas? Thanks. Answer Assuming that create_time contains th…
Select distinct returns duplicates
I have the following query: But it returns duplicates in TK.TICKETID attribute. And if i remove other attributes all ok. e.g. How can I return only a single record per TK.TICKETID? Answer Try this:
Magento: domain change from old to new domain and hosting troubles
There are troubles when uploading backup of old website domain to new hosting domain. Now I got many errors and it seems it is with the database . Problem is that, that I do not understand how does SQL working . And also it’s looks like that new domain complaining with old domain name. It means I need t…
Postgres: getting latest rows for an array of keys
I have a simple table for the events log: If I need the latest event for a given user, that’s obvious: However, suppose I need the latest events for each user id in an array. For example, for the table above and users {1, 4} I’d expect events {3, 5}. Is that possible in plain SQL without resorting…
query hbase like normal sql
I know Hbase is not like normal SQL. But is it possible to query Hbase something like this? select row-key from Table where cf:first=”ram” and cf:middle=”leela” and cf:last=”ban”; // ram(first …
Best way to start SSIS catalog or SSIS package remotely
I need to execute an SSIS package or an SSIS catalog remotely. What is the best way to acomplish this? I’m using: Visual Studio 2012 SQL Server 2012 Answer I am almost positive you need an integration server to accomplish this. The package is stored in the MSBD of the integration server and called by jo…
Set server output only in spool
Is it possible to set the server output only into the spool file and not in the shell ? Inside MY_PROCEDURE I have this : I would like to put Hello World only in log.txt, not in the screen shell. Answer Simplest way is to pipe the unix output to /dev/null
Query combinations with nested array of records in JSON datatype
I’m working on a Rails application that utilizes the Postgres JSON data type. I have a JSON column called data in a table called reports. Let’s say I have multiple entries like this: What I would like to do is return the different combinations of entries that have the same album, src, and backgrou…