Use where instead of join

use where instead of join # using WHERE ANSI-89 syntax SELECT * FROM TABLE_A a, TABLE_B b WHERE a.id = b.id # using JOIN ANSI-92 syntax SELECT * FROM TABLE_A a JOIN TABLE_B b ON b.id = a.id
use where instead of join # using WHERE ANSI-89 syntax SELECT * FROM TABLE_A a, TABLE_B b WHERE a.id = b.id # using JOIN ANSI-92 syntax SELECT * FROM TABLE_A a JOIN TABLE_B b ON b.id = a.id
tsql cte in a transaction BEGIN TRANSACTION ;WITH CTE ….. SELECT…..etc. COMMIT TRANSACTION
trigger in mysql syntax CREATE TRIGGER trigger_name {BEFORE | AFTER} {INSERT | UPDATE| DELETE } ON table_name FOR EACH ROW trigger_body;
sum of column in sql SELECT SUM(column_name) FROM table_name WHERE condition; sum sql SELECT SUM(column_name) FROM table_name WHERE condition; how to find averages on sql SELECT AVG(column_name) FROM table_name WHERE condition; select count sql SELECT COUNT(column_name) FROM table_name WHERE condition;
sqlalchemy filter getattr q = session.query(myClass) for attr, value in web_dict.items(): q = q.filter(getattr(myClass, attr).like(“%%%s%%” % value))
sql set default value datetime now ALTER TABLE YourTable ADD CONSTRAINT DF_YourTable DEFAULT GETDATE() FOR YourColumn
sql server substring SELECT SUBSTRING(‘SQL Tutorial’, 1, 3) AS ExtractString; substring sql SELECT SUBSTRING(‘SQL Tutorial’, 4, (LENGTH(‘SQL Tutorial’)) AS LastCharactersString; //Result -> Tutorial grab part of a string sql SELECT Â Â Â Â SUBSTRING(‘SQLTutorial.org’, Â Â Â Â Â Â Â Â POSITION(‘.’ IN ‘SQLTutorial.org’));
sql server check port number USE master GO xp_readerrorlog 0, 1, N’Server is listening on’ GO #LogDate ProcessInfo Text #… Server Server is listening on [ ::1 <ipv6> 1434]. #2.. Server Server is listening on [ 127.0.0.1 <ipv4> 1434].</ipv4></ipv6>
sql examples from your work Select * from external_patients where “patientId” = 55424; Select * from patients where “patientId” = 55424; Select * from patients where “firstName” like ‘%JohnDoe%’; Select * from users where “userId” = 12345; etc.
sql constraint check value in list ALTER TABLE <table> ADD CONSTRAINT chk_val CHECK (col in (‘yes’,’no’,’maybe’))</table> sql constraint check value in list CREATE TABLE test( _id BIGINT PRIMARY KEY NOT NULL, decision NVARCHAR(5), CHECK (decision in (‘yes’,’no’,’maybe’)) );