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.
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: - SELECT * FROM booking
-
WHERE userid = '5'
-
OR userid LIKE '5,%'
-
OR userid LIKE '%,5'
-
OR userid LIKE '%,5,%'
-
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: - SELECT * FROM booking
-
WHERE userid = 5
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).
This query is not working.
SELECT * FROM `ebooking` WHERE `userid`='5'
Because i want to match only one id ('1,4,5,6').
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: - SELECT * FROM booking
-
WHERE userid = '5'
-
OR userid LIKE '5,%'
-
OR userid LIKE '%,5'
-
OR userid LIKE '%,5,%'
-
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/ Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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?
|
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")...
|
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...
|
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 =...
|
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 =...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
|
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
|
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...
| |