Skip to content

Tag: sql

How to copy parent and child data from one database to another while assigning the newly created parent ids in the foreign key column of child tables?

Suppose, I have a table tblClasses and tblStudents Now each class have multiple student. tblStudents now, I have another server having exact same db and tables and I am copying data from server 1 to server 2 from same tables using the Select and Insert e.g. and for tblStudents now this is ok but the real prob…

How do I translate this specifik SQL statement to LINQ

SQL: C# Objects: Monitor: And Counter: And the objects that I need to turn it into is: AllStatistics: I don’t have much experience with LINQ so the most I’ve achieved with it is somethig like: My question is, how would I compose an LINQ statement with the same functionality of the above SQL query …

Table data show one by one record different two tables?

Table 1 ABC DEF GS PM BS PK Table 2 ABC DEF YZ TT UG KK Need output ABC DEF GS PM YZ TT BS PK UG KK So please help me sql query Answer table1: Azbuka Def A1 D1 A2 D2 A3 D3 A4 D4 table2: Azbuka Def F1 H1 F2 H2 F3 H3 F4 H4 Result: Azbuka Def

Get value for every date in table with date ranges

I’m working with table, its structure looks like this: from_date DATE %Y-%m-%d to_date DATE %Y-%m-%d person VARCHAR tax INT Table shows that in period between date_from and date_to for such person there was such tax The whole point is that these periods can intersect and activities can sum. Roughly spea…

SQL GROUP BY IN CASE STATEMENT

i have one table i would like to classify the apple as below i try to add code as below, but its not like what I expected I try this code also, but got error Answer You want conditional aggregation here, which involves summing over the CASE expression:

Junction table in PostgreSQL

I have two tables I created a junction table called “recipes_ingredients” My first question is: is it correct how I created the “recipes_ingredients” table? Do I need the “id” or I can just have the two foreign keys “fk_recipe” and “fk_ingredient”? A…