473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Select 5 rows with criteria 1 and 2 rows with criteria 2

2
Hi all. I have been trying to write a code in a query that selects 4 questions defined as Electrical and 2 questions defined as safety and 2 questions defined as tools. These questions are in the same table. The pickel is, i also want to random select those questions from my database (table). Here is my code to random select each one from DataBase table,
DataBase = Table with all questions. ( ID | Type | Question | Answer | )

SELECT TOP 4 DataBase.*
FROM DataBase
WHERE (Type In (Electrical))
ORDER BY Rnd(IsNull(DataBase.ID)*0+1);

Now i also want to select the rest and also have them random selected.
I dont seem to be able to do so in one query.
Is there any one that has any suggestions for me?
Any help much appreciated, with regards Heimir
Jul 19 '07 #1
2 1679
JKing
1,206 Expert 1GB
Hi I think the best way to acheive this is to use multiple queries and then bring them together into one. I attempted to do this in a single query however the multiple subqueries crashed access for me. So I think this is the way to go.

qselElec
SELECT TOP 4 tblQuestion.ID
FROM tblQuestion
WHERE (((tblQuestion.Type) In ('Electrical')))
ORDER BY Rnd(IsNull(ID)*0+1);

qselSafe
SELECT TOP 2 ID
FROM tblQuestion
WHERE (Type In ('Safety'))
ORDER BY Rnd(IsNull(ID)*0+1);

qselTools
SELECT TOP 2 ID
FROM tblQuestion
WHERE (Type In ('Tools'))
ORDER BY Rnd(IsNull(ID)*0+1);

qselQuestions
SELECT DISTINCT tblQuestion.Type, tblQuestion.Question, tblQuestion.Answer, tblQuestion.ID
FROM tblQuestion, qselElec, qselSafe, qselTools
WHERE (((tblQuestion.ID) In ([qselElec].[ID],[qselSafe].[ID],[qselTools].[ID])));
Jul 19 '07 #2
Heimir
2
Thank you so much!

You gave me the hint to realize what i needed to do.
Use multiple queries, that was the solution.
Thanks
Jul 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
12
by: TP | last post by:
Here is my problem. I need to display a table about which I have no information except the table name. Using metadata I can somehow show the column names and record values. But my table has 1...
1
by: BF | last post by:
Hello, I am trying to find out if there is a way to limit the number of rows returned when a cursor is opened. I am using DB2 version 7 on z/OS. The SELECT statement in my DECLARE CURSOR...
6
by: ronchese | last post by:
Hi. I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working! In one of my tests, I have a datatable with 1 row and...
4
by: Aryan | last post by:
Hi, I am having problem with DataTable.Select() method. I am using ASP.NET 2.0. I have DataSet which reads data from XML file using DataSet.ReadXML(). Now this dataset has various datatable,...
4
by: Chris | last post by:
Can't seem to figure out how to do this and have been reading for some time now...... I want to select a row count from a table name in SYSTABLES. This statement does not return what I needed,...
20
by: talktozee | last post by:
Hey, everyone! Basically, I need to insert *multiple rows* into table A from table B based upon some criteria, and I need to insert some static values along with each row from table A. For...
0
by: Jeff | last post by:
..NET 2.0 I'm working on a .NET 2.0 project which are using a DataSet for all communication with the database. Here is the problem: I want to search a table based on a matching criteria (I...
2
newnewbie
by: newnewbie | last post by:
I am learning VBA and need a little help with a macro that I am writing. I have a worksheet with data that I split into multiple worksheets based on criteria in one column. E.g. Column A has unique...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.