Tag Info

New answers tagged


Chain your insert with data-modifying CTEs: WITH ins0 AS ( INSERT INTO siteInfo (siteName, siteHost, notes, ... ) VALUES ('Sample', 'sample.com', 'note', ... ); RETURNING siteid ) INSERT INTO siteLinks (siteID, URL) SELECT siteid, 'test' FROM ins0; Or use lastval() or currval(): BEGIN; INSERT INTO siteInfo (siteName, siteHost, notes, ... ) ...


Yes, it is possible to return both results without repeating the subquery by rewriting your query using an outer join. The following will return same results as your version: SELECT COUNT(*) AS `count` FROM agreements AS ag LEFT JOIN ( SELECT a.driv_id, a.veh_id FROM agreements a INNER JOIN ...

Top 50 recent answers are included