473,324 Members | 2,548 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,324 software developers and data experts.

How to match only a single value in field with multiple values?

hi everyone

I have one user table where userid store and another booking table where i store userid like(3,4,5,8)this for only some user who have access to show booing records.
if userid is '5' how i fetch only those record which match on booking table(userid).



please help me.
Sep 26 '10 #1

✓ answered by pod

If I read you right, you have a list of IDs in each record:

booking table (id,userid,record)
where "id" is a unique ID for the record
and "userid" is a list of uid from your user table


this is not a good database design, therefore it complicates your queries a bit but there is a solution although a bit heavy:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM booking 
  2. WHERE userid = '5' 
  3. OR userid LIKE '5,%' 
  4. OR userid LIKE '%,5' 
  5. OR userid LIKE '%,5,%' 
  6.  
where "%" is a wildcard

this will work for a query looking for one userid but when looking for multiple userids, it will get heavier and more complicated

---------------

you should consider the following database design:
USER table [uid, name]
BOOKING table [id,record] where each record contains one booking with its unique ID
USER_BOOKING table [id,uid]where each record contains a user ID and a booking ID

this last table could have multiple user IDs for the same booking ID
...
look up some good relational database tutorial, it will really help understanding SQL and all
http://www.phlonx.com/resources/nf3/

5 2156
Atli
5,058 Expert 4TB
Hey.

Could you show us the exact structure of these tables?
Also, which database system is this? MySQL?

Have you tried simply:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM booking
  2. WHERE userid = 5
Sep 26 '10 #2
user table [uid, name]
Booking table [id,userid,record]
i have used mysql database.
In booking table (id,userid,record)values insert as ('1','1,4,5,6','text')...
if uid is '5' then how i fetch only those record which match on booking table(userid).
Sep 27 '10 #3
pod
298 100+
Try Atli' s code and I strongly suggest you read up on SQL as well, check this site tutorial:

http://www.w3schools.com/sql/default.asp
Sep 27 '10 #4
This query is not working.
SELECT * FROM `ebooking` WHERE `userid`='5'

Because i want to match only one id ('1,4,5,6').
Sep 27 '10 #5
pod
298 100+
If I read you right, you have a list of IDs in each record:

booking table (id,userid,record)
where "id" is a unique ID for the record
and "userid" is a list of uid from your user table


this is not a good database design, therefore it complicates your queries a bit but there is a solution although a bit heavy:

Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM booking 
  2. WHERE userid = '5' 
  3. OR userid LIKE '5,%' 
  4. OR userid LIKE '%,5' 
  5. OR userid LIKE '%,5,%' 
  6.  
where "%" is a wildcard

this will work for a query looking for one userid but when looking for multiple userids, it will get heavier and more complicated

---------------

you should consider the following database design:
USER table [uid, name]
BOOKING table [id,record] where each record contains one booking with its unique ID
USER_BOOKING table [id,uid]where each record contains a user ID and a booking ID

this last table could have multiple user IDs for the same booking ID
...
look up some good relational database tutorial, it will really help understanding SQL and all
http://www.phlonx.com/resources/nf3/
Sep 27 '10 #6

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

Similar topics

2
by: vasanth kumar | last post by:
Hi, I have a problem in dealing with the return value of the SQL command. I know how to do, when SQL command returns Recordsets. But in my case it returns a single value. The following code fails...
1
by: Brett | last post by:
I often have to change a single value in an xml file based off of a given ID. Is there any easy way to do this through .net.xml? Do I have to parse the file then write it out again?
8
by: Tom | last post by:
Here is what I do to get a single value from my database (using Oracle ODP as example): Dim ID as Object Dim cmdTest as New OracleCommand("select ID from MyTable where key = " & KeySearch")...
3
by: Bill Nguyen | last post by:
VS.NET 2003 SQLserver 2000 I need to create a function to return the single resulting value from an SQL statement. For example, "Select max(amount) from tableA" I would like to reuse the...
4
by: Jim in Arizona | last post by:
I'm having trouble pulling a single value from my SQL DB and filling a string type with it. Something like: Dim strConnection As String =...
7
by: Peter | last post by:
Gday, I have a dataset with multiple tables, from which I want to access a single value in one of those tables. I know I can do something like: Decimal myVar =...
3
by: Dave | last post by:
Hi I am using .NET 2 with c# and want to retrieve a single value from my stored procedure. I currently have the following code: ...
1
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
Is it possible to compare a single value to many in a single statement? Here is what I am attempting to do: 1. Users lands on page and via a cookie check function they are identified. 2. A query...
3
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method...
1
by: psycho | last post by:
How do we return a single value from a stored procedure. Suppose I have a stored procedure like this: create proc dbo.spInsertGroup @ID uniqueidentifier @GroupName varchar(100), @IsActive...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.