I have Table A with 60 million records and Table B with 20 million records and I am joining those tables based on key columns . (inner join on a.id=b.id)
I am able to fetch the results within 10 minutes . After that for validating another column in Table C (I am joining the result generated from Table A and Table B ) with Table C(30 million records) and joining the column b with column c.(inner join on b.prfl_id=c.prfl_id)
But the query is very slow and it is running for more than 30 minutes and even then result is not generated. Any suggestion to get the results fast.
Thanks in advance for your suggestion .
Regards,
Saravanan
Related
I have a table (A) having 200,000 records. I have created a backup table (B) from the same table (A) which contains around 100,000 records. Now I have to delete all the records which are present in table B from the parent table A.
I am using the below query:
delete from A where id in (select id from B);
The query which I am using is taking a lot of time, the delete is happening very slowly. Could someone please help me in reducing the time taken while deleting the records??
Any help will be appreciated.
How about creating a table with the records you want to keep, dropping the old A table, and renaming the new one back to A?
A query like:
Create table C
Select A.*
From A Left Outer Join B ON A.id=B.id
Where B.id is null
should perform well if id is indexed.
I have a table with a key and 9 columns (say A) other tables with only a key (say B), now I have to join table A with B on the key and repeat that 9 columns 30 times. can someone suggest some ideas?
just join can be done if only 9 columns have to be attached but the problem is I have to attach 30 times.
Suppose that I have two queries from two databases as below.
LIST 1 from [Alphabet] table
ABCD
A
B
C
D
LIST 2 from [Integers] table
Numbers
101
201
301
401
I would like to merge them so that in Excel sheet, I want to see that alphabet table is in columns A and integers table is in column B.
Here my suggestion:
Create Table merged ( Select [ABCD] from [Alphabet] join with [Numbers] from [Integers])
How can I improve the quality to work?
And should the row numbers be equal in both tables? Say, 27 letters and 27 integers, or would work with 27 letters and integers [1,20]?
This Is My First Answer and i hope it would help ...Back to your question
How can I improve the quality to work?
You Must use constraints to enforce rules for the data in your tables.
You need two columns of the same type, one on each table [Alphabet table] and [Integers table], to JOIN on.
Whether they're primary and foreign keys or not doesn't matter.
And should the row numbers be equal in both tables?
the answer is No
Depending on what joins you will Use !
SQL joins are used to query data from two or more tables, based on a relationship between the corresponding rows in these tables.
• INNER JOIN: Returns all corresponding rows from multiple tables.
• LEFT OUTER JOIN: Returns all rows from the left table, corresponding rows in the right table & if there are no matches, returns NULL.
• RIGHT OUTER JOIN: Returns all rows from the right table, corresponding rows in the left table, & if there are no matches, returns NULL.
I have two tables (with same structure). One with 80 million records and other with 60 million records.
I want to delete records in 80m table that match in 60m table.
I use a sql query as below:
DELETE FROM tbl_80M
FROM tbl_80M INNER JOIN
tbl_60M ON tbl_80M.MobileNumber = tbl_60M.MobileNumber
In two tables, we have index on mobilenumber fields.
I run above query and it takes a long time .
Is there a better way to reach result in shorter time?
Note: tbl_80M has all of records that is in tbl_60M . I want to find and delete all records that are common in tbl_80M and tbl_60M.
Have you tried writing a query to insert those N million records into a new table and then drop the old tables.
Then at last you can rename new table to tbl_80M.
SELECT
* INTO tbl_NM
FROM tbl_80m a,
tbl_60m b
WHERE tbl_80M.MobileNumber = tbl_60M.MobileNumber
I am new to VBA so I apologize in advance if this seems basic to you experts but I appreciate all of the help I can get.
I have a table containing a column of reference numbers that can grow or shrink weekly. I also have a query pulling back price list data that has changed since last week. The query results vary weekly. What I need to do is assign all of the query results to each reference number and have all of that end up in a make table. For example if there are 10 reference numbers and the query result is 10 rows then 100 lines would be added to the table (adding the reference number to the beginning of each row). This sounds like some sort of loop but your the experts, not me.
Thanks in advance!
You can solve it with a cross join. In a cross join you join two tables without specifying a join clause. Such a query returns all possible combinations of rows of the two tables (this is called a Cartesian product)
SELECT col_a, col_b INTO newTable
FROM table_a, table_b
If table_a contains 10 rows and table_b contains 5 rows, this returns 50 rows.