Skip to content

Tag: sql

Hibernate Check Annotation

I have a table with three fields, say a, b, c. I would like to add a constraint ensuring that if a is not null, then also b and c are not null. I have done that using following SQL Is there a way to achieve same effect using hibernate annotation @Check? I can’t find a helpful example with that

SQL: Two select statements in one query

I want to select information from two SQL tables within one query, the information is unrelated though, so no potential joints exist. An example could be the following setup. tblMadrid tblBarcelona I want to have a query that gives me the following: I tried to follow this logic: Multiple select statements in …

Is order preserved after UNION in PostgreSQL?

Here is the code: As you can see the recursive code gives the result in right order, but the non-recursive code does not. They both use union, why the difference? Answer Basically, your query is incorrect to begin with. Use UNION ALL, not UNION or you would incorrectly remove duplicate entries. (There is noth…

How to check active transactions in SQL Server 2014?

I am using SQL Server 2014 and want to know how to check my active transactions? Answer Query with sys.sysprocesses DBCC OPENTRAN : helps to identify active transactions that may be preventing log truncation. DBCC OPENTRAN displays information about the oldest active transaction and the oldest distributed and…

sql query “WHERE IN”

I have this query : When I execute it it returns the message: Incorrect syntax near ‘)’. What is the problem? Answer That’s because, your IN clause has no parameter/argument WHERE BeneficaryID IN (). It should be WHERE BeneficaryID IN (id1,id2,id3, …,idn) Your current query is same as …

UPDATE mysql rows

I’m trying to update a lot (close to 500) of rows in mysql database. How can I make it with just 1 query? …and it goes on and on until 500. Answer Use the BETWEEN operator: If not all products with an ID in that range should be updated, you’ll have to use the IN operator and construct the qu…

PL/SQL: procedure to process a comparison between two tables

This is an example what i need : Table 1 : Table 2: A procedure that feeds a table3 as a result of comparison between the table 1 and table 2 Table 3: Please, i need help if someone had the same challenge 🙂 Answer Data setup: The below query would give you the differences

where does woocommerce store orders?

I’m looking in the sql db and I can see something that resembles orders inside wp_posts . However, I would expect them to be inside the tables beginning with wp_woocommerce. Can anyone shed some light on this phenomenon? Cheers Answer In woocommerce orders are modelled as a custom post type so they are …