473,473 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

need help in this query

49 New Member
Hello everyone.
guyz can you please help me in this query

id | name | lastname | status | hrs

1 qwe sss 1 5
2 rtyy zax 1 5
3 bvgf hyv 1 5
4 bvgd vbcf 1 10
5 cvxx hopy 1 10
6 bcxd loiu 1 10


now what i want to achieve is that......
first four records when hrs>1 or hrs<5 and last four records when hrs>5 and hrs< 10
and how can i manage same scenario when there will be lots of record

looking forward for your response

Regards
Jul 14 '08 #1
6 1465
coolsti
310 Contributor
Hello everyone.
guyz can you please help me in this query

id | name | lastname | status | hrs

1 qwe sss 1 5
2 rtyy zax 1 5
3 bvgf hyv 1 5
4 bvgd vbcf 1 10
5 cvxx hopy 1 10
6 bcxd loiu 1 10


now what i want to achieve is that......
first four records when hrs>1 or hrs<5 and last four records when hrs>5 and hrs< 10
and how can i manage same scenario when there will be lots of record

looking forward for your response

Regards
Unless you are not explaining what you wish to do well enough, I do not understand what you really want.

Consider your first query: you want the first 4 records when hrs>1 or hrs<5. In your above table, each and every row matches this criterion. So there is no basis for extracting only the first 4 rows using only the problem statement that you show here.

Same goes for your second query.

You need to state more precisely what you want, and how it would be extrapolated to when there are more rows in the table (do you still want the first 4 and the last 4 respectively?). And then it can be decided if your problem statement will allow for a unique solution.
Jul 15 '08 #2
chaarmann
785 Recognized Expert Contributor
1.) use "select" to retrieve the wanted records
2.) use "limit" to retrieve only the needed number.

If you are not sure how to do that, read in the SQL manual about these words (or google for them, or read an online SQL course for beginner etc.)
Jul 15 '08 #3
amitpatel66
2,367 Recognized Expert Top Contributor
Try to use UNION clause here:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT * from table1 WHERE hrs > 1 AND hrs < 5
  3. UNION
  4. SELECT * FROM table1 WHERE hrs > 5 AND hrs < 10
  5.  
  6.  
Jul 15 '08 #4
Muddasir
49 New Member
thanks a lot ppl

okay I will try to put my question more clearly.

Normally if we want to fetch any record against any specific value we use e.g. "WHERE hr=2" and in the result se we will get a row of record having hr=2, and no result when colum hr doesnot have value= 2 right !.

I am asking is it possible that we can get results even when colum hr doesn't have value=2. can we get the results against colum (hr) value = 5..... means if not exact value is entered can we get result near to that value....say if 2 is entered we can get all result where hr=5 if 7 is entered we can get all results where hr=10. and so on..

hope this time i am clear in my question

sorry for my bad english

regards
Jul 16 '08 #5
coolsti
310 Contributor
In order for you (or for us to help you) to make a query to do what you wish to do, you must first be able to describe precisely, either in words or mathematically in the form of an algorithm, what it is you wish to do.

For example, if you wish to select only the records where hrs is equal to the value 3, you of course have the where clause "where hrs = 3".

If you wish to select only the records where hrs is "within 2 of the value 3", this translates mathematically to a value of hrs that lie between and including 3-2 and 3+2. And this then gives you the where clause "where hrs >= (3 - 2) and hrs <= (3 + 2). Here I write the where clause with 3-2 instead of 1 and 3+2 instead of 5, because what you might wish to do is to have the value central value of 3 be a variable which is changed from query to query.

What I am saying is, try to state as mathematically as possible the "general rule" that you want to use to select your rows, and then it is easier for us to help.
Jul 16 '08 #6
amitpatel66
2,367 Recognized Expert Top Contributor
Are you looking at something like:

get the records if hrs is > 2 and <= 5? - this will give you all the revords with hr = 3 or 4 or 5

hrs > 5 and hrs <= 10 -- this will give you all the records with hr = 6 or 7 or 8 or 9 or 10

So what are you exactly looking at?..I am sorry but still I am not able to understand what exactly you are looking at.
Jul 16 '08 #7

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
3
by: pw | last post by:
Hi, I am having a mental block trying to figure out how to code this. Two tables: "tblQuestions" (fields = quesnum, questype, question) "tblAnswers" (fields = clientnum, quesnum, questype,...
7
by: K. Crothers | last post by:
I administer a mechanical engineering database. I need to build a query which uses the results from a subquery as its input or criterion. I am attempting to find all of the component parts of...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
10
by: L. R. Du Broff | last post by:
I own a small business. Need to track a few hundred pieces of rental equipment that can be in any of a few dozen locations. I'm an old-time C language programmer (UNIX environment). If the only...
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: id ------------ name
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: ----------------
3
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.