473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

mySQL get information from multiple tables with efficient query

I'm new to MySQL, and cannot seem to get the desired information out, after trying a few different google searches, and reading through some MySQL tutorials.


Given the following sample tables:

Table 1(Activity This is activity table which is send to the clients):
Expand|Select|Wrap|Line Numbers
  1.  
  2. ID  sendingid         list        fromaccount    
  3. 1        a1        user_new1        noreply@example.com
  4. 2         a2        user_new1        noreply@example.com
  5. 3         a3        user_new2        noreply@example.com
  6. 4         a4        user_new4        noreply@example.com
  7.  
  8.  
Table 2(Tracking - This is the main task tracking table,which track which user opened our activity):
Expand|Select|Wrap|Line Numbers
  1.  
  2. ID  trackingid         emails            
  3. 1        a1        myexampla@gmail.com
  4. 2         a2        example@hotmail.com 
  5. 3         a3        newexample@yahoo.com
  6. 4         a4        simpler@gmail.com
  7.  
Table 3(user_new1- This is the list which is attached with activity send under the column name list):
Expand|Select|Wrap|Line Numbers
  1.  
  2. ID  fname         emails                    price
  3. 1        John        myexampla@gmail.com      10
  4. 2         Bill        example@hotmail.com      20
  5. 3         sami        newexample@yahoo.com      20
  6. 4         daweoo        simpler@gmail.com        20
  7.  
The user_new1,user_new2,user_new3 .......user_new80 tables. All tables have similar structure.

first i will find unique email address from tracking table then i find to which list of the activity table it is send,
then i will delete that record from list say user_new1 and move it to another temprary table
Jun 26 '12 #1
5 2520
Rabbit
12,516 Expert Mod 8TB
You should not have multiple tables for user_new. It breaks normalization rules and makes querying difficult, as you've already seen. It should be just one table.
Jun 26 '12 #2
yes infact it will make difficult,but i need solution for it.
is it possible in two queries if yes please tell me the method how to write then that.
but you must remmeber i have millions of records in my database
Jun 26 '12 #3
Rabbit
12,516 Expert Mod 8TB
My suggestion is that you fix your data.

But if you have to work around it, use a union query to simulate the correct data structure, or build a dynamic string and execute that.
Jun 26 '12 #4
can you show me some code how can i do this,
also as i mention we have hug data,join query will run slow in this case or not
Jun 26 '12 #5
Rabbit
12,516 Expert Mod 8TB
A join query doesn't have to be slow. It's all based on how well the data is designed. And currently your data is badly designed. So yes, it may well be slow, but that has nothing to do with using a join or a union.

Sorry, I don't give out code unless the poster has shown an attempt.
Jun 26 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Jay | last post by:
Hi everyone ! I hope someone will be able to help me with this problem. I currently have several tables in MySQL database. Below is my table structures. (Data type for each fields are...
0
by: Petre Agenbag | last post by:
Hi List Me again. I'm trying to return from multiple tables, the records that have field "information_sent" between two dates. The tables are all related by means of the id of the entry in the...
1
by: Ray | last post by:
Hello all, I am attempting to delete multiple rows from multiple tables as follows: DELETE FROM attachments,responses,response_lines WHERE attachments.id IN(2,7,11) AND...
8
by: Rigga | last post by:
Hi, I am new to mysql and need help on how to join tables. I have a database which contains 4 tables, the main table contains information by date order and the other 3 contain data also in date...
1
by: wireless | last post by:
We recently added a new database at the company. It has only one purpose - to hold massive amounts a daily data generated by telephone calls on a network. The amount of data was so large...
8
by: Jason L James | last post by:
Hi all, does anyone know if I can create a dataview from multiple datatables. My dataset is constructed from four separate tables and then the relationships are added that link the tables...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
4
AaronL
by: AaronL | last post by:
Hello again, First I want to say thank you to all of you that have helped me in the past with all of my questions. I have gotten far in PHP and MySQL in the past two weeks. I designed a site...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.