SQL Query needed for fetch value from Two identical table but not fully identical table
SELECT *, NULL AS Field4 FROM TableA WHERE Field1 NOT IN (SELECT Field1 FROM TableB) UNION ALL SELECT * FROM TableB
SELECT *, NULL AS Field4 FROM TableA WHERE Field1 NOT IN (SELECT Field1 FROM TableB) UNION ALL SELECT * FROM TableB
Tables in SQL don’t have a defined order (they might have, depending on the concrete implementation, but you cannot count on it). If you require a certain ordering, you must order your result set when selecting. Therefore, I can see two possibilities: Update every id above the ‘missing’ row, and insert your new row using … Read more
There are several problems with Query 1. First, why does it have trailing ))? Either they shouldn’t be there, or there are some missing ( elsewhere. Second, the placement of the EXCEPT is wrong. The example is this… SELECT sname FROM … WHERE NOT EXISTS (…) EXCEPT SELECT bid FROM … But it appears that, … Read more
Did you mean to write CREATE TABLE catsub1…, without the $? Is the table name catsub1, or are you trying to insert the value of the $catsub1 variable as the table name? In this case, you need to set the value of $catsub1 properly because apparently it is now 0. $catsub1 = “your_table_name”; $sql = … Read more
select to_char(systimestamp,’YYYY-MM-DD”T”HH24:MI:SS.FF2TZHTZM’) from dual; 2018-02-07T11:43:37.47+0800
Use a single query that joins the two tables, instead of doing nested loops. SELECT p.* FROM posts AS p JOIN friends AS f ON p.postby = f.friendId ORDER BY p.posttime DESC From your comment, it appears your first query isn’t so simple. But you can join with a subquery. SELECT p.* FROM posts AS … Read more
You’ll have to get the percentage of the year worked and multiply it by the salary. If the joined_date is before January of that year, use ‘1.00’. Since you did not specify a SQL type, I chose MSSQL as I’m most familiar with it. Here’s an example using MSSQL: DECLARE @yearToFindSalaryFor INT = 2018 DECLARE … Read more
That table is really a very bad design. Anyway, here you have the code. It uses dynamic sql: DECLARE @sql nvarchar(max) SET @sql = N’CREATE TABLE TheMostStupidTableIHaveEverSeen(ID int, Name varchar(100)’ DECLARE @i int = 1 WHILE @i <= 598 BEGIN SET @sql = @sql + N’, A’ + CAST(@i AS nvarchar(4)) + N’ int’ SET … Read more
Using the sample data you posted (and adapting it slightly), here is my attempt to solve the problem: SELECT BASESCORE, Datediff(dd, MINDATE, MAXDATE) FROM (SELECT BASESCORE, Cast(Max(DATETIME) AS DATETIME) MaxDate, Cast(Min(DATETIME) AS DATETIME) MinDate FROM table1 GROUP BY BASESCORE)T You can take a look at the full working version on SQL Fiddle. Let me know … Read more
You could serialize / Deserialize the JSON as String. Use JPA Converters, which shall automatically convert the same. Suggest to use Jackson JAR for the same.