last day (14 days later) » 

2:55 PM
0
A: update empty attributes with select

EhsanTIf you had a Primary Key for you table table2, it would be better, but since your subqueries return only one row, the you still can combine these two queries in one query like this: $sql = "insert into table(Attribute, col1, col2, col3, col4) select t2_1.".$attrib[$i].", MIN(cast(t2_1.".$attrib[...

 
Your code was like this, I can change it for you, So please tell me, you want the value of Attribute field always be the value of State field?
 
Solved it Thanks.
 
:) great, you are welcome
 
sorry for interrupting you again. what if i do it for the class=0. i am repeating the code and giving it name t2_3 and at the last add the condition with t2_3.Class=0. but it's not inserting anything not even the previous records which works fine without adding this code.
 
What to you mean by saying what if i do it for the class=0? if you want to change class=1 to class=0 just change it, but if not, please elaborate on how do you want to add the new condition?
 
2:55 PM
$sql = "insert into range_table(Attribute, col1, col2, col3, col4, col5, col6) select '$attrib[$i]', MIN(cast(t2_1.".$attrib[$i]." as decimal(5,1))), MAX(cast(t2_1.".$attrib[$i]." as decimal(5,1))), MIN(cast(t2_2.".$attrib[$i]." as decimal(5,1))), MAX(cast(t2_2.".$attrib[$i]." as decimal(5,1))), MIN(cast(t2_3.".$attrib[$i]." as decimal(5,1))), MAX(cast(t2_3.".$attrib[$i]." as decimal(5,1))) from table2 as t2_1, table2 as t2_2 where t2_2.Class = 1, table2 as t2_3 where t2_3.Class = 0";
 
OK, then just move table2 as t2_3 to from clause. like this: from table2 as t2_1, table2 as t2_2, table2 as t2_3
 
Then where to put where conditions. as t2_2 and t2_3 have different conditions.
 
from table2 as t2_1, table2 as t2_2, table2 as t2_3 where t2_2.Class = 1 and t2_3.Class = 0
Hi
 
this code takes so much time isnt there is any easy way?
its loading and loading and loading :(
is there an alternate for this code ?
 
Your database is not optimized
You do not have primary key on you table, then I assume you do not have any indexes either
Am I right?
 
3:04 PM
yeah
 
OK, then it's obvious that It takes time!
 
i put primary keys as id
how could primary key helps ?
 
With this query it can not, but since you did not have primary key, then I guessed you do not have index as well
how many records do you have in your table? more than 1 million?
 
around 4000
 
ok, then your query should take less than 0.5 seconds at most
please put an index on class field
a normal index your do the job
 
3:09 PM
how to do that ?
im a newbie so sorry i dnt knw that much
 
Do you have access to your mysql databse?
like phpmyadmin?
 
yeah
 
OK, select your database and table(table2) and in the sql tab type this:
alter table table2 add index(class);
and run it
 
ok
 
then because you are using min and max, then you can put indexs on the fields you are using in you min and max
you can add index on these fields 'one', 'two', 'three', 'four', 'five', 'six' on table2 as well
 
3:28 PM
the query is still loading
the query of indexing class
 
3:49 PM
Then I think your mysql server in busy or has some problems, that query should execute in a blink
Then I think your mysql server in busy or has some problems, that query should execute in a blink
 

last day (14 days later) »