Dana Mon, 7 Sep 2020 12:26:14 +0200, Jan Novak <repcom@gmail.com> napis'o:
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and
server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i
get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the
ip Table, if more then one ip's saved there.
group by... count... and then select those >1.
https://www.w3resource.com/sql/aggregate-functions/count-with-group-by.php
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i
get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the
ip Table, if more then one ip's saved there.
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i
get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the
ip Table, if more then one ip's saved there.
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i
get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the
ip Table, if more then one ip's saved there.
Jan
Dana Mon, 7 Sep 2020 12:26:14 +0200, Jan Novak <repcom@gmail.com> napis'o:
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and
server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i
get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the
ip Table, if more then one ip's saved there.
group by... count... and then select those >1.
https://www.w3resource.com/sql/aggregate-functions/count-with-group-by.php
On 07/09/2020 11:26, Jan Novak wrote:
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and
server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved,
i get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from
the ip Table, if more then one ip's saved there.
Jan
order by....unique
On 07/09/2020 12:52, Nikolaj Lazic wrote:
Dana Mon, 7 Sep 2020 12:26:14 +0200, Jan Novak <repcom@gmail.com>distinct.. Not unique as I said earlier
napis'o:
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and
server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i >>> get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the >>> ip Table, if more then one ip's saved there.
group by... count... and then select those >1.
https://www.w3resource.com/sql/aggregate-functions/count-with-group-by.php >>
Am 07.09.20 um 14:15 schrieb The Natural Philosopher:
On 07/09/2020 11:26, Jan Novak wrote:
Hi,
i have a table "server" with auto_increment field ID and a table
"ip", with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and
server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are
saved, i get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from
the ip Table, if more then one ip's saved there.
Jan
order by....unique
sorry, i dont understand.
What should be orderd abd unique set?
Am 07.09.20 um 14:19 schrieb Jan Novak:
Am 07.09.20 um 14:15 schrieb The Natural Philosopher:
On 07/09/2020 11:26, Jan Novak wrote:
Hi,
i have a table "server" with auto_increment field ID and a table
"ip", with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and
server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are
saved, i get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from
the ip Table, if more then one ip's saved there.
Jan
order by....unique
sorry, i dont understand.
What should be orderd abd unique set?
(Sorry for my bad english)
The complete sql string is like that (with additional Infos from "port" table):
select port.VALUE as "port", ip.VALUE as "ip" from server, port, ip
where server.DELETED=0 and server.ID=port.SERVER_ID and server.ID=ip.SERVER_ID
In ip Table are for a host 4 rows, but i like to have for the host only
the first one.
Hi,
i have a table "server" with auto_increment field ID and a table "ip",
with a filed "SERVER_ID" corrosponding to "server.ID"
select ip.VALUE as "ip" from server, ip where server.DELETED=0 and server.ID=ip.SERVER_ID
If in "ip" table for the server are more then one ip adress are saved, i
get in my results the server also more then one time listed.
My question is: how can i get only the server with the first IP from the
ip Table, if more then one ip's saved there.
It does have two sub selects, which can slow things down a lot if you
don't have indexes.
What do you mean as first?
- Lowest ip-number (string or value vise)?
- Highest ip-number (string or value vise)?
- First line inserted for the server (lowest id or oldest timestamp)?
FROM server
s
INNER JOIN (SELECT MIN(p2.PORT_ID) PORT_ID, p2.SERVER_ID FROM port p2
WHERE p2.SERVER_ID = s.SERVER_ID GROUP BY p2.SERVER_ID) AS port2 ON port2.SERVER_ID = s.SERVER_ID
INNER JOIN (SELECT MIN(i2.IP_ID) IP_ID, p2.SERVER_ID FROM ip i2 WHERE i2.SERVER_ID = s.SERVER_ID GROUP BY p2.SERVER_ID) AS ip2 ON
ip2.SERVER_ID = s.SERVER_ID
INNER JOIN ip i ON i.SERVER_ID = server.ID
and i.IP_ID = ip2.IP_ID
INNER JOIN port p ON p.SERVER_ID = server.ID
and p.PORT_ID = port2.PORT_ID
WHERE server.DELETED = 0
It does have two sub selects, which can slow things down a lot if you
don't have indexes.
The complete sql string is like that (with additional Infos from "port"My question is: how can i get only the server with the first IP from >>>>> the ip Table, if more then one ip's saved there.
table):
select port.VALUE as "port", ip.VALUE as "ip" from server, port, ip
where server.DELETED=0 and server.ID=port.SERVER_ID and
server.ID=ip.SERVER_ID
In ip Table are for a host 4 rows, but i like to have for the host only
the first one.
As Kees said in his reply to you, you need to define what you mean by "first".
Here is one possibility, rewritten to use explicit joins instead of implicit joins:
SELECT server.ID, MIN(port.VALUE) AS "port", MIN(ip.VALUE) AS "ip"
FROM server
INNER JOIN ip ON ip.SERVER_ID = server.ID
INNER JOIN port ON port.SERVER_ID = server.ID
WHERE server.DELETED = 0
GROUP BY server.ID
But MIN() is only one possible way to select a single IP or port out of those available.
You need to decide how you want to choose.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 295 |
Nodes: | 16 (2 / 14) |
Uptime: | 01:07:24 |
Calls: | 6,642 |
Calls today: | 2 |
Files: | 12,190 |
Messages: | 5,325,418 |