# NewId()

**URL:** <https://forum.kirupa.com/t/newid/183485>\
**Category:** programming\
**Created:** [March 27, 2006, 2:14pm UTC](https://forum.kirupa.com/t/newid/183485 "2006-03-27T14:14:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pucca](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@pucca](https://forum.kirupa.com/u/pucca)\
**Post date:** [March 27, 2006, 2:14pm UTC](https://forum.kirupa.com/t/newid/183485/1 "2006-03-27T14:14:59Z")

</div>

I want to random select 5 records from my database… I got this code,

```auto
SELECT Top 5 * FROM comptbl ORDER BY NewID()

```

but its gives me an error saying “[FONT=Arial][SIZE=2]Undefined function 'NewID() in expression.”  
What must I do?

thanks for the help! [/SIZE][/FONT]:puzzled:  
[FONT=Arial][SIZE=2]  
[/SIZE][/FONT]

---

<div class="post-metadata">

**Author:** ![JoshuaJonah](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/joshuajonah/32/1775_2.png) [@JoshuaJonah](https://forum.kirupa.com/u/JoshuaJonah)\
**Post date:** [March 27, 2006, 2:25pm UTC](https://forum.kirupa.com/t/newid/183485/2 "2006-03-27T14:25:26Z")

</div>

I think you are looking for the rand() function. Look [here](http://ca.php.net/manual/en/function.rand.php).

you can use that to got a random number in certain range then combine that with your MySQL select statement.

---

<div class="post-metadata">

**Author:** ![pucca](https://avatars.discourse-cdn.com/v4/letter/p/5f8ce5/32.png) [@pucca](https://forum.kirupa.com/u/pucca)\
**Post date:** [March 27, 2006, 3:07pm UTC](https://forum.kirupa.com/t/newid/183485/3 "2006-03-27T15:07:03Z")

</div>

sorry man, but the sites actually done in asp. It’s a access database?.. Don’t know asp that well?..☹
