I have a webpage with an identifier as a variable GETthat I need to pull out name, cityand statefor that identifier (stored in 1 table), as well as any data associated with it (stored in another table).
These are the results of a single query:
SELECT
info.name, info.city, info.state,
data.data1, data.data2, data.data3, data.data4
FROM
data_table data,
info_table info
WHERE
data.id = 12345 AND info.id = data.id
name | city | state | data1 | data2 | data3 | data4
---------------------------------------------------
test | temp | AL | 12 | 9 | 1 | 14
test | temp | AL | 63 | 8 | 1 | 6
test | temp | AL | 46 | 66 | 1 | 723
test | temp | AL | 7 | 5 | 2 | 99
test | temp | AL | 4 | 2 | 3 | 0
test | temp | AL | 2 | 11 | 1 | 1
But the data for the column name, city, stateeverything will be the same for each row, so I might as well do it with two queries and return the "right" amount of data (but obviously twice as much time to communicate with the server):
SELECT
info.name, info.city, info.state,
FROM
info_table info
WHERE
info.id = 12345
name | city | state
-------------------
test | temp | AL
... and ...
SELECT
data.data1, data.data2, data.data3, data.data4
FROM
data_table data,
WHERE
data.id = 12345
data1 | data2 | data3 | data4
-----------------------------
12 | 9 | 1 | 14
63 | 8 | 1 | 6
46 | 66 | 1 | 723
7 | 5 | 2 | 99
4 | 2 | 3 | 0
2 | 11 | 1 | 1
, , 2 , ? - () , , , ?
, , total server communication time / 2 > time to transmit extra data, ?