Left join vs two queries, which is faster? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Supposing I have two tables to query, which query should I choose?
Left join between them or two separate queries? Which option is faster?
Same question on three tables (so basically double left join vs. three queries), which is faster?

i think only one query is better. But you should try in your SQL Server both queries and see which take a longer time

Join query is intoduced for faster data fetching..It consumes execution time..So no doubt join query is much faster...When you use seperate query then each time it has to go database and fetch result but when join all queries,it needs only single time travel to db...

Related

how do can I add multiple rows after using Inner join on two tables [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have two tables in mysql db. The two tables are connected through a key :
five_day_general_information.days_dates_id = five_weekly_day_calander.id
SELECT
five_weekly_day_calander.Total_working_days
FROM five_day_general_information
INNER JOIN five_weekly_day_calander
ON five_day_general_information.days_dates_id = five_weekly_day_calander.id
WHERE five_day_general_information.Pro_id = 133;
enter image description here
AS YOU SEE IN THE PICTURE,
How can I add the 5 and 2 and return the results which is 7 so I can use that results in php
I think you just want aggregation:
SELECT SUM(fwdc.Total_working_days) as Total_working_days
FROM five_day_general_information fdgi JOIN
five_weekly_day_calander fwdc
ON fdgi.days_dates_id = fwd.id
WHERE fdgi.Pro_id = 133;
You can refer to the returned value as Total_working_days in the PHP result set.
Note that table aliases make the query easier to write and to read.

Query db with in exlusion [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Trying to query db. I need to show all fields, but need to exclude one name that is in the db.
Example:
The db contains column 'marketer' when I try to query it I don't want marketer 'Tommy' but all the others. I have tried tried where clause with all the names and not working.
This is the query you're looking for
SELECT * FROM <table_name> WHERE marketer<>'Tommy';
use the 'where' to add your conditions
SELECT * FROM your_table WHERE marketer!='Tommy'
For your Reference
http://www.w3schools.com/sql/sql_where.asp

How to make this MySQL query execute faster? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
SELECT * FROM (`collection_series`)
JOIN `datadatexnumericy` ON
`collection_series`.`series_id` = `datadatexnumericy`.`series_id`
JOIN `saved_users_chart` ON `collection_series`.`collection_id` =
`saved_users_chart`.`chart_id`
WHERE `saved_users_chart`.`chart_id` = '265'
AND `saved_users_chart`.`id` = '6' AND `datadatexnumericy`.`x` >=
'1973-09-30' AND `datadatexnumericy`.`x` <= '2014-06-30' AND
`datadatexnumericy`.`series_id` != '43538'
AND `datadatexnumericy`.`series_id` != '43541'
GROUP BY YEAR(datadatexnumericy.x)
This is my SQL query and result of this query I am getting from AJAX response this query is working fine but I am getting response slow a bit I think the problem is in my SQL query.
I want all matching records from collection_series and datadatexnumericy table and only matching row from saved_users_chart is there any possible way to optimize this query in more efficient way so that I can get ajax response faster.
In my opinion your query is already optimized. You should test the result of the query in an SQL server to see response time of SQL server and then compare with the time you actualy receive the response back from server.
If is not necesary to extract all the columns from each table, then manualy enter the column names instead of *. By doing this the response received from server will be certainly smaller, therefore it will be faster.

mysql insert unique values from one column to a column of another table [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
please help me in this matter: I need to copy the unique values from entries_list.nr_comanda_entries to entries_uploaded.ship_id.
The tables have these values in common: entries_list.file_id = entries_uploaded.id
Both tables have many other columns, only the entries_uploaded.ship_id is empty.
Could you please tell me the mysql query to do that?
You could use an UPDATE query and an INNER JOIN:
UPDATE
entries_uploaded INNER JOIN entries_list
ON entries_list.file_id = entries_uploaded.id
SET
entries_uploaded.ship_id = entries_list.nr_comanda_entries
Please see fiddle here.

Insert each result of an array into separate SQL rows? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a query that is returning a different amount of user_id's each time it's run (based on the number of subscribers).
What I need to do is insert each of these user_id results into separate rows within a table along with a simple message of "new alert" in a separate column.
How could I possibly go about doing this? Would a for each loop work in this situation?
Try this:
INSERT INTO alert_table SELECT user_id, 'new alert' FROM ... WHERE ...
Use your own query, just prepend it with the INSERT INTO alert_table clause.

Categories