Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我无法使用mysql从具有内部联接的数据库中选择数据_Php_Mysql - Fatal编程技术网

Php 我无法使用mysql从具有内部联接的数据库中选择数据

Php 我无法使用mysql从具有内部联接的数据库中选择数据,php,mysql,Php,Mysql,我无法从数据库中选择数据 我的表格结构如下所示 客户表 id name 10 geetha 客户国家表 id cust_id country 1 10 6 2 10 16 我是这样得到结果的 customer name country geetha 6 geetha 16 但我只想获得一个客户的数据一次,即不重复 customer name co

我无法从数据库中选择数据

我的表格结构如下所示

客户表

id      name
10      geetha
客户国家表

id    cust_id  country

1       10      6
2       10      16
我是这样得到结果的

customer name      country


geetha             6
geetha             16
但我只想获得一个客户的数据一次,即不重复

customer name      country


geetha             6
我的问题是

SELECT customer.name,customer.id,customer_country.country_id, customer_country.cust_id
    FROM customer
    INNER JOIN customer_country on customer.id = customer_country.cust_id

如果在
customer\u country
表中有重复项,则需要选择其中一项。下面是一个使用
max()
的方法:

如果要将所有这些内容都列在一个列表中,请使用
group\u concat()


仅适用于第一条记录,适用于结尾:限制1

    SELECT customer.name,customer.id,customer_country.country_id,
    customer_country.cust_id from customer 
    inner join customer_country on customer.id= customer_country.cust_id limit 1

试试这个,我在customer\u country.cust\u id之前添加了distinct

SELECT customer.name,customer.id,customer_country.country_id, distinct customer_country.cust_id
FROM customer
INNER JOIN customer_country on customer.id = customer_country.cust_id

您想要第一个还是最后一个插入的国家id?
    SELECT customer.name,customer.id,customer_country.country_id,
    customer_country.cust_id from customer 
    inner join customer_country on customer.id= customer_country.cust_id limit 1
SELECT customer.name,customer.id,customer_country.country_id, distinct customer_country.cust_id
FROM customer
INNER JOIN customer_country on customer.id = customer_country.cust_id