我有一种情况,我需要从同一个表的有效数据中生成包含随机数据的行
我通过PHP rand($min,$max)函数生成ID,$min = 1,$max = [SELECT MAX(ID)FROM patient] – 1
Select tblFirstName.FirstName,tblLastName.LastName,tblBirthDate.BirthDate,tblLocation.Location From (SELECT FirstName FROM patient WHERE ID > 11445 AND FirstName != '' LIMIT 1) AS tblFirstName,(SELECT LastName FROM patient WHERE ID > 74964 AND LastName != '' LIMIT 1) AS tblLastName,(SELECT BirthDate FROM patient WHERE ID > 26360 LIMIT 1) AS tblBirthDate,(SELECT Location FROM patient WHERE ID > 68356 AND Location != '' LIMIT 1) AS tblLocation
现在在ID>从上述查询26360得到的26360是随机数>用于避免26360被删除的可能性
问题:
试试这个:
SELECT (SELECT FirstName FROM patient WHERE ID > 11445 AND FirstName != '' LIMIT 1) AS tblFirstName,(SELECT Location FROM patient WHERE ID > 68356 AND Location != '' LIMIT 1) AS tblLocation