Tag Info

New answers tagged


In MySQL You can try a function create function modul_id() returns INTEGER DETERMINISTIC NO SQL return @modul_id; create view v (your select... where modul_id = modul_id()...); select * from (select @modul_id:=14 modul_id) m, v; not tested on your query...


This query will return 8 similar posts to the current post we are viewing. The number 5 is placeholder. It need to be overridden by variable. SELECT SIMILARITY(title, (SELECT title FROM gallery WHERE id=5)) AS sim, title, uri FROM gallery WHERE title % (SELECT title FROM gallery WHERE id=5) AND id!=5 ORDER BY sim DESC LIMIT 8;


It means the number of columns you select in the top query must be the same as the number of columns in the second. If you don't have the same number, you can work around it. Below I can add a NULL to the second query because it's missing a third column. SELECT col1,col2,col3 FROM t1 UNION ALL SELECT col1,col2, NULL FROM t2


Simple approach (can split sets) Chain DELETE and INSERT with a data-modifying CTE for best performance and to be safe: WITH del AS ( DELETE FROM tbl t WHERE udate < (now() - interval '1 year')::date AND EXISTS ( -- is not the greatest SELECT 1 FROM tbl WHERE compid = t.compid AND seq > t.seq RETURNING ...


This would also work: SELECT COUNT(*) FROM ans_checkups WHERE (SELECT visit1_date AS visit UNION ALL SELECT visit2_date UNION ALL SELECT visit3_date UNION ALL SELECT visit4_date ORDER BY (visit IS NULL) LIMIT 1 OFFSET 2 -- one less than 3 ) IS NOT NULL ; and this ...


Something like (untested): select * from <table> where if(visit1_date,1,0)+if(visit2_date,1,0)+if(visit3_date,1,0)+if(visit4_date,1,0) >= 3; should do the trick.


Simple , just try to adapt the following code insert into prices (group, id, price) select 7, articleId, 1.50 from article where name like 'ABC%';


If the (subquery) has SELECT (whatever expression) AS col FROM ..., then you can do: INSERT INTO mytable (col1, col2, col3, col4) SELECT val1, s.col, val2, val3 FROM (subquery) AS s ; or: WITH s (col) AS (subquery) INSERT INTO mytable (col1, col2, col3, col4) SELECT val1, s.col, val2, val3 FROM s ;

Top 50 recent answers are included