Beginner's Question: How To Write This Query

Jul 14, 2007

Hi -

I feel stupied b/c I can't figure this out but I hope it's just a few seconds for some of the more senior posters of this forum:

I have a table that looks like this:

Table:Request
ID: bigint
... (a bunch of table specific columns)
User_Status_ID: bigint (holds the bigint ID of the status table, below; always holds the ID to the most recent ID, if several)
Provider_Status_ID: bigint (holds the bigint ID of the status table, below;  always holds the ID to the most recent ID, if several)

and then there is a second table that looks like this:

Table: Status
ID: bigint
RequestID: bigint (the request ID, so I can see all status messages for the request)
Time: Timestamp
Code: byte (there are only a few status messages)

The status table holds both the status for users and providers, as they use exactly the same status code. What I'd like to get is a table/view that looks like this:

RequestID:bigint (the request that this status belongs to)
User_Code: byte (the code of th most recent user status)
Provider_Code: byte (the code of the most recent provider status)

Somehow, I am blanking how to create a query that returns both user and provider codes in one row. Any help greatly appreciated!!!!

 

Oliver

View 2 Replies


ADVERTISEMENT

Beginner Query Question

Apr 11, 2003

I have a query returning the Average of an Integer with a precision of zero. However because of this in my query and export I am only returning whole numbers for my Average.

Is there anyway in the query to modify the field for what I want to view so that it will return decimals?

Thanks in advance.

Don

View 1 Replies View Related

Beginner--Create SQL Query

Jan 19, 2008

I'm an Absolute beginner to SQL

I have a table of baseballTeams with columns baseballTeamName and a baseballTeamID

A have another table (baseballGames) which consists of baseball games which includes a homeTeamID and a visitingTeamID.
Both of these columns are linked to the baseballTeamID from the baseballTeams table

I have been successful at joining the two tables and Selecting the baseballTeamName from the baseballTeams table for either the hometeam or
visiting team as shown below:

SELECT gameID, homeTeamID, baseballTeamID,baseballTeamName
FROM baseballGames, baseballTeams
WHERE baseballGames.homeTeamID=baseballTeams.baseballTeamID


...but I cannot figure out how to select BOTH the homeTeam name and the visitingTeam name from the baseballTeam table

Any help would be greatly appreciated

Thanks in advance

Larry

View 6 Replies View Related

Beginner Question - SQL Query

Feb 15, 2008

Hello there,

Say I have the following table:


ID Type Name
--- -------- ---------------
1 1 Michael
2 1 Julian
3 2 Catherine
4 2 Julia
5 2 Silvia
6 3 John

What SQL query should I use in order to get the following output:

Type Name1 Name2 Name3
------- ----------- ------------ ------------
1 Michal Julian NULL
2 Catherine Julia Silvia
3 John NULL NULL

I believe this is a very basic question, but I can't seem to find the answer anywhere.

View 5 Replies View Related

[absolute Beginner] Help For SQL Basic Query Exercise

Apr 29, 2008

hi

i am learning SQL basic commands ( like , where, having, group by, order by , join ,and simple sub-query) and I got one exersice I cannot solve

table RECIPE has 3 columns , ( pizza ,ingredient,amount)
each pizza could use 1 / many ingredient, each ingredient could be used by 0 / 1/ many pizza, amount means the quantity of that ingredient used in certain pizza

question:
(List the ingredients, and for each ingredient, also list the pizza that contains the largest amount of this ingredient.)

============================
Raw data :

recipe
======
pizza ingredient amount
--------------------------------
margarita spice 5
margarita cheese 120
ham ham 150
ham spice 5
napolitana anchovies 100
napolitana olives 75
napolitana spice 10
hawaiian ham 100
hawaiian pineapple 100
hawaiian spice 5
cabanossi cabanossi 150
cabanossi spice 10
siciliano onion 50
siciliano capsicum 75
siciliano olives 50
siciliano anchovies 50
siciliano spice 15
americano salami 120
americano pepperoni 75
americano spice 10
mexicano onion 75
mexicano capsicum 75
mexicano mushroom 50
mexicano chilli 25
mexicano spice 20
seafood seafood 200
seafood spice 5
garlic garlic 25
garlic spice 10
vegetarian onion 50
vegetarian capsicum 50
vegetarian mushroom 50
vegetarian peas 50
vegetarian tomato 50
vegetarian spice 5
mushroom mushroom 100
mushroom spice 5
special cheese 25
special tomato 25
special ham 25
special anchovies 25
special olives 25
special mushroom 25
special bacon 25
special egg 25
special pineapple 25
special cabanossi 25
special salami 25
special capsicum 25
special onion 25
special peas 25
special seafood 25
special spice 10
stagiony ham 75
stagiony mushroom 50
stagiony olives 50
stagiony anchovies 25
stagiony spice 10


====================================================

Query Results needed:


ingredient pizza amount
------------------------------
anchovies napolitana 100
bacon special 25
cabanossi cabanossi 150
capsicum mexicano 75
capsicum siciliano 75
cheese margarita 120
chilli mexicano 25
egg special 25
garlic garlic 25
ham ham 150
mushroom mushroom 100
olives napolitana 75
onion mexicano 75
peas vegetarian 50
pepperoni americano 75
pineapple hawaiian 100
salami americano 120
seafood seafood 200
spice mexicano 20
tomato vegetarian 50

=============================================

Thanks

View 10 Replies View Related

Query Execution Failed For Dataset (Beginner)

Jun 26, 2007

I got this Error, Query Execution for Dataset 'Source'.



When i try to run a report that is actually a drillthrough from another report. It runs fine in Report Designer, and when i deploy to my Local server. But when i deploy it to my virtual Report Server, I get this error messege. Why is it doing this? and where can i see errors for this type of stuff, so i can figure this out. This uses the same Datasource as the report linked from it. That report works fine, why wont this one? any ideas?

View 8 Replies View Related

Need Help To Write The Query

Sep 13, 2006

Hi, I have a table Projects. This table has ProjectID and Version as PK. The Version starts at 1 and everytime a project is changed, I save the project with the same ProjectID and increase the Version by 1.How can I create a query that get all Projects with the latest Version? Thx

View 1 Replies View Related

How Do I Write This Query?

Oct 28, 2006

I have a Properties table like thisPropertyID   PropertyValue     1              Address     2             City     3             Stateetc.and a UserProfile table like thisUserID   PropertyID   PropertyValue1               1               123 Main Street1                2               Denveretc.How do I write a query that can populate a registration page  with Address,City, State as labels and 123 Main Street, Denver, as TextBox text?

View 4 Replies View Related

How To Write Query For This Using C#?

Feb 10, 2008

Hi,I have included here my webform here.i need some assistance here with code.my webform contains two parts.the 1st part is office info and the 2nd part is client info.i also have two table named office_info and client_info.1st part is populated from the table office_info as soon as the office name is chosen from the dropdownlist.in my scenario,when user selects officename from dropdownlist,then textboxes correspondingto address and email gets populated by the related data from table office_info.2nd part is client info.here there are 3 textboxes(for name,age,address) to collect the data from the client using the form.these data gets posted to new row in table client_info as soon as user clicks on the save button.Now my actual question starts here.when user selects the option from the dropdonwlist the office info displays,now when he fills the client info part and clicks the save button,i want all the data to go to the table client_info in such a way that all the data fromthe client info part plus the id of the office also go along with it.eg: when user clicks the save button.i want data to get submitted in table client_info in this way.(id,name,age,address,off_row_id) (1,jack,25,US,1) here off_row_id is the id from the below table.my table office_info is like this (id,off_name,address,email)                                         eg(1,xyz,ny,xyz@xyz.com)    well can anyone tell me how to write query to do insert,edit,update,delete query in this case using c#  and sql?here is the scenario <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server">    <title>Untitled Page</title></head><body>    <form id="form1" runat="server">    <div>        Office Info:<br />        <hr />        <br />        Office name:        <asp:DropDownList ID="DropDownList1" runat="server" Width="63px">            <asp:ListItem>ABC</asp:ListItem>            <asp:ListItem>XYZ</asp:ListItem>        </asp:DropDownList><br />        <br />        &nbsp;Address:        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />        <br />        email:        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />        <br />        <hr />        </div>        Client info:<br />        <br />        &nbsp;name:        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />        <br />        &nbsp;age: &nbsp;        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br />        <br />        &nbsp;address:<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox><br />        <br />        <br />        <hr />        <asp:Button ID="Button1" runat="server" Text="save" />        <asp:Button ID="Button2" runat="server" Text="cancel" />    </form></body></html> thanks.jack.      

View 8 Replies View Related

How To Write Sql Query With Asp.net(C#)?

Feb 11, 2008

 hello everyone. i want to know how asp.net works with sql database. can i have a link to the article where i can perform from basic to advance sql query using asp.net(C#)? (in context of vwd 2005 and sql express ) thanks. jack. 

View 1 Replies View Related

Please Help Me To Write A Sql Query

May 21, 2008

I have two table named tbl_Scale and tbl_NGTrDAMaster
tbl_Scale(ScaleID,ScaleName,ScaleLB,ScaleUB,ScaleSI1,ScaleSI2,ScaleSI3) here scale id is prim key
tbl_NGTrDAMaster(TrDaId,ScaleID,CityTypeID,DAAmount) no prim key
and we get CityTypeID from xml databinder.......
In my form thr is two drop down list one for scale name and another for city type id
this is the data form  tbl_NGTrDAMaster
 17 1 1 555 18 3 1 777 19 3 1 999 8 1 1 777 5 5 1 34634 20 1 1 52352 27 1 1 6666 23 5 1 12412 12 2 1 235235 13 3 1 456456 14 5 1 1000000 15 4 1 60000 16 5 1 90 24 5 1 25123 25 5 1 13124 26 5 1 12412
but i am expecting only one combination of set.....
like 1-1,1-2,1-3,1-4.......but if reenter 1-1 thn we have to restrict that....
please help me....
i am in big trouble......Thanx in advance
If my qes is not clear for everyone...
plz tell me....
i try my lebel best for understand my prob to u.....

View 2 Replies View Related

How To Write This Sql Query?

Jun 2, 2004

i have a table
tab
col1 col2 num
A a 30
A b 20
B a 10
B b 40
C a 50
C b 40

now i want get col1 by distinct col1 ,and order by num, as the result:
col1
C
B
A

so can someone help me to write this "select..."

View 3 Replies View Related

How Can I Write This SQL Query ??

May 17, 2005

Hi
 
I have 2 tables and I want to Get information from that tables by SQL Query but How Can I writ this SQL Query ? .. My target as Follow
 
Class Table
-------------------------------------------------
ClassID       ClassName
1             AA
2             BB
 
Student Table
-------------------------------------------------
StudentID     StudentName   ClassID
1             Student 1     1
2             Student 2     1
3             Student 3     2
4             Student 4     1
5             Student 5     2
6             Student 6     1
 
 
How Can I Writ SQL Query to get result like the following ..
 
--------------------------------------------------
ClassID       ClassName     StudentCount
1             AA            4
2             BB            2
 
 
My SQL Query must get all Class table column plus column content the count of student in each class
 
 
And thanks with my regarding
 
Fraas
 

View 3 Replies View Related

How To Write This Query

May 12, 2006

Hello,
I have a table with fields; T1: Dept, Name, Desc, ModificationDate
How can I group by T1.Name, T1.Desc and bring T1.Dept which has the latest T1.ModificationDate
Can anyone write me this query?
 

View 3 Replies View Related

How To Write This SQL Query?

Nov 26, 2003

CUSTOMER
Name City IndustryType
Abernathy Construction Willow B
Amalgamated HousingMernphisB
Manchester LumberManchesterF
Tri-City BuildersMemphis B

ORDERS
NumberCustNameSalespersonNameAmount
100Abernathy ConstructionZenith560
200Abernathy ConstructionJones1800
300Manchester LumberAbel480
400Abernathy ConstructionAbel2500
500Abernathy ConstructionMurphy6000
600Tri-City BuildersAbel700
700Manchester LumberJones150
800 Abernathy Construction Abel 75000

SALESPERSON
NamePercentOfQuotaSalary
Abel63132000
Baker3846200
Jones2649500
Kobad2739600
Murphy4255000
Zenith59129800

I have got the three tables above.
Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
Thank you very much!

View 1 Replies View Related

How To Write This SQL Query?

Nov 26, 2003

CUSTOMER
Name City IndustryType
Abernathy Construction Willow B
Amalgamated HousingMernphisB
Manchester LumberManchesterF
Tri-City BuildersMemphis B

ORDERS
NumberCustNameSalespersonNameAmount
100Abernathy ConstructionZenith560
200Abernathy ConstructionJones1800
300Manchester LumberAbel480
400Abernathy ConstructionAbel2500
500Abernathy ConstructionMurphy6000
600Tri-City BuildersAbel700
700Manchester LumberJones150
800 Abernathy Construction Abel 75000

SALESPERSON
NamePercentOfQuotaSalary
Abel63132000
Baker3846200
Jones2649500
Kobad2739600
Murphy4255000
Zenith59129800

I have got the three tables above.
Would you help me to write a SQL query to show the names and PercentOfQuota of sales people who have an order with all cuatomers.
Thank you very much!

View 1 Replies View Related

I Appreciate If Anyone Help Me To Write This Query

Apr 5, 2006

User Page Name Permission
vijay customer.aspx 1
vijay customer.aspx 2
vijay customer.aspx 3
vijay user.aspx 2
Rajashekar customer.aspx 1
Rajashekar customer.aspx 2

Where Permission 1 = SAVE
2 = UPDATE
3 = DELLETE

Where I query on User and PageName I want the output as

User Page Name Permission
vijay customer.aspx 1,2,3
vijay user.aspx 2
Rajashekar customer.aspx 1,2

View 2 Replies View Related

Better Way To Write This Query?

Feb 23, 2006

i am assuming there is a better way to write this query (since im not too proficient in SQL)


sql Code:






Original
- sql Code





select client_id from clients where client_id not in
(select schedule_det.client_id from schedule_det,
schedule_mstr where schedule_det.schedule_id=schedule_mstr.schedule_id
and schedule_mstr.status_code!='COMPLETE')






 SELECT client_id FROM clients WHERE client_id NOT IN     (SELECT schedule_det.client_id FROM schedule_det,             schedule_mstr WHERE schedule_det.schedule_id=schedule_mstr.schedule_id            AND schedule_mstr.status_code!='COMPLETE') 

View 2 Replies View Related

How Do I Write This Query

Nov 30, 2004

ok i have table1, table 2 and table 3.

these table have some common feild names. table1,2 and 3 all have a,b,c and d as field names. each table has other field names too but the ones they all have in common are a,b,c and d.

so i would like to write a query that returns all rows from all 3 tables where column d is greater than 5 and less than 10.

so basically i want it to treat the records from all 3 tables ad one big dataset.

how would i write a query to do this.

i know i could say:
SELECT a,b,c,d
FROM table1,table2,table3

but what gets me is the WHERE clause

do i have to say WHERE table1.d >5 AND table1.d <10 OR table2.d>5 AND table2.d <10 OR table3.d>5 AND table3.d <10

??

any guidance please?

View 4 Replies View Related

Help Need To Write A Query

Jun 9, 2008

Hello all,

I need a help to write a query. Here is the table

Declare @Test Table
(
EName Varchar(15)
)

Insert into Ename
Select 'a' Union all
Select 'a' Union all
Select 'a' Union all
Select 'b' Union all
Select 'c' Union all
Select 'b' Union all
Select 'd' Union all
Select 'g' Union all
Select 'g'.

Now i need a result like

a0
a1
a2
b0
b1
c0
d0
g0
g1

Could any one can help me to wite this query..?


Thanks
Lakshmi.S

View 4 Replies View Related

How To Write QUERY

Apr 9, 2007

Hi
i want to audit a tables
For That i created audit tables
In that table i want to store data as
all field related to old data table
and from which system user had changed the data

For this system id i used host_id() but the iam not getting the id



Malathi Rao

View 6 Replies View Related

Help Me Write This SQL Query....

Jan 28, 2008

I have a table with many records in it. There is one field called "Nature". How would I select the value that appears the most often in the "Nature" field? The nature field contains text.

For example, this code selects those with more than 10 records...

I just want the top record.

SELECT count(*) FROM WEBASGN_FULL GROUP BY NATURE HAVING count(*) > 10

Basically select nature from webasgn_full that occurs the most often in the table....

Thanks

View 8 Replies View Related

How Best To Write This Query?

Oct 19, 2007

I need help on writing a query which will return my results as I need them.

I have three tbls.

TimeType, TimePlan and TimeSpent

TimeType simply lists the Individual Jobs (types) a user can be doing.

The TimePlan and Time Spent each list individual records with start and end dates and what TimeType was being performed.
Each TimeType can have multiple starting and ending dates for the TimePlan and Timespent.

I need my results to show individual timetypes, with the starting and end dates for the Timeplans and also the TimeSpent

EG:

TypeType | TimeplanStart | TimeplanEnd | TimeSpentStart | TimeSpentEnd

Writing | 01/02/2007 | 02/02/2007 | |
Writing | | 03/02/2007 |

So there will be multiple Types, and for each one I need to show the start and end dates.

I would normally write this as three seperate queries.

The first would get the TimeTypes,
The second the TimePlan starting and ending dates for that type,
The third , the Spent starting and ending dates for that type


However that doesn't come across as very efficient so I wonder if there was any other alternative

View 14 Replies View Related

How To Write A Query

Nov 2, 2006

Please help me to get this result
 
Bellow is my requirement
I have employee table which stored employee information
And I have reference table which holds information for that employee reference
 
I need to count from the reference table like how many reference made for male Employee and female depending on their age range
 
 
 
I have a selection list: Gender: Male
                                                  Female
                                                  All
 
When user select                      : Male from the list
 
Male    Female                         Age range: 20-29         Age range: 30-45
120      0                                              100                              20
 
When user select                      : Female from the list
 
Male    Female                         Age range: 20-29         Age range: 30-45
0          25                                            15                                10
 
When user select                      : All from the list
 
Male    Female                         Age range: 20-29         Age range: 30-45
120      25                                            115                              30
 
 
Please help me to sort out this problem
regards
Sujithcf

View 1 Replies View Related

Help To Write Query...

Oct 6, 2006

Hi !

There is one table tCustomers. It has following columns: ID, Name, Code...

By the mistake in this table has appeared incorrect records (duplicates).

How can I write the query to find them ?

I tried:

Select c.ID ID1,s.ID ID2, c.NAME NAME1,s.NAME NAME2, c.Code C1, s.Code C2, From tCustomers c, tCustomers s
where c.Code=s.Code and c.ID <> s.ID

But the result is not that I expected

View 1 Replies View Related

How To Write This Query

Nov 27, 2007



I have a Table "T1" with col "id","name".
Table "T2" with "TID","ID" etc..d
[Here, id of T1 is mapped to id of T2]

Now, I wanted to write a query such that the query should output T1.id,T1.name and a third column which will show me the count of records in T2 corresponding to an ID in T1.

Any help on this is highly appreciated.

Thanks!

View 6 Replies View Related

How To Write This Query?

Nov 7, 2006

hi guys,

I run into this question again. Here is it.
I have two tables like this:
StoreVisit(StoreVisitID(PK), UserID, StoreID, LoginID, LogoutID)
ProductOrders(ProductID, UserID, StoreID, OrderQuantity, StoreVisitID)
What I want to do is, I need to find out the lastest store visit record and put the StoreVisitID into ProductOrders table for the same userID, StoreID. So what I tried is:

update ProductOrders set StoreVisitID=sv.StoreVisitID
from ProductOrders po
inner join (select top 1 * from StoreVisit where UserID=po.UserID and StoreID=po.StoreID order by StoreVisitID desc) sv
on po.StoreID=sv.StoreID and po.UserID=sv.UserID
Where po.UserID=@UID and po.StoreVisitID is null

When I run it, it shows the error:
The column prefix po, does not match with a table name or alias name used in the query.
Looks like it does not recognize the po in select top 1... .

I hope you guys already understand what I am trying to do. I am wondering what is the best way to do this?
Thanks.



View 1 Replies View Related

How Do I Write A Query To Display Top 9 Plus Others

Feb 12, 2007

I have query that return statuses and their totals, the data looks like:
StatusCode     Total----------    ---------A              100PS             50SI1            9SI2            8etc...
The query returns over 30 totals, but I only want the top 9 totals plus others (the rest of the totals combined) .
How do I go about this query?
StatusCode     Total----------    ---------A              100PS             50SI1            19SI2            18SI3            9SI4            8PS1            6PS2            6PS3            6Others         99 
 Also, have it work for queries that have 9 or less totals?
 
 
 
 
 
 
 
 

View 7 Replies View Related

Urgent - How To Write Query In Asp.net

Sep 26, 2007

i am working on asp.net 
i am passing two values through querystring to the next page, that values are comming to next page but i want to display results on these two crieria hats.
i have written following query which working fine in sql server 2000
 SQL 2000==> select caterername, ccity from caterer where ccity='matunga' and cateringfor like '%event%'
but when i am trying to do this  in asp.net its not working. following code accepting only one value . i want to compair two value. Please guide me how to write above query in asp.net using 'and' and 'like' operatorasp.net ==>select * from addahall where HCity='" + city + "'  ==> city is variable
 please let me know as early as possible i have very less time.
 

View 5 Replies View Related

Bit Of A Complicated SQL Query To Try And Write...

Feb 12, 2008

I'll start by giving the basic idea of the data structure I'm looking at in the database (pardon my MS Paint skills!):

And this all starts with a root plan. So (taking projects out of the picture for the minute), it could be a structure going any number of levels down like so: plan -> goal -> strategy -> plan -> goal -> strategy -> plan -> goal -> strategy, etc.And not forgetting, that a strategy can also have any number of projects, and all these relationships are one to many, so it ends up being like a large tree structure.
What I am trying to accomplish is user security related, in that I need to enforce rules set to say whether a single user is allowed to view a project. You can define the rules at any level in the structure above. So if for instance, a user is given a rule that they can access anything from a goal, they can see any projects that exist in any strategies underneath that goal in the tree structure. I hope this is making sense so far... The rules can also just be defined at a specific project level.
These rules (at the moment, I'm more than happy to change if this is a silly way of doing it) are set in a table that has the columns:user_id intplan_id intgoal_id intstrategy_id intproject_id intallow bitEvery row will have a user_id value, and one of either a plan_id, goal_id, strategy_id or project id (which I thought would be a simple way to pull out what kind of rule if needed), and the allow column just defines if it's an allow or deny rule (a specific deny rule on any object lower in the tree structure will override any cascaded allow rule).
The way my application needs to grab this information, is to simply have some way of returning a list project_id values for which the current user is allowed to access. I'm basically stumped. The closest I have gotten (which still didn't quite work) was going to end up using quite a large number of cursors... Which is bad. It can be inefficient to an extent, as once these values are gathered once, I can store them in a Session variable, so it's not grabbing them every time the user tries to load a project.
Thanks for any help!

View 4 Replies View Related

How To Write Sql Query For This Case?

Aug 31, 2005

In one SQL server table table1 it contains following data
ID Date
CA01-001 01/01/2000
CA01-002 02/01/2000
CA01-003 01/15/2000
CA01-004 02/11/2000
CB02-001 01/01/2001
CB02-002 02/01/2001

ID is grouped by first four characters CA01 or CB02, then each record increased by 1 to be 001, 002 .. untill 999 in sequence

How do I write SQL query just to get each group largerest record such as for our case:
CA01-004 02/11/2000
CB02-002 02/01/2001

Thanks in advance!

View 1 Replies View Related

Trying To Write A Replace Query

Aug 24, 2001

I can't figure out how to replace a single digit entry in my database with a new digit. i want to replace in the alarms.severity all values of 4 with a new value of 2. For some reason the script I wirte won't get past the digit 4 in the statement. Anyone have a script they can let me try?

View 1 Replies View Related

How To Write A Query For 1st, 2nd, 3rd Max Salary

Apr 18, 2006

employee table having columns employeeid, salary

i want to write a query to get 1st, 2nd and 3rd max salary ?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved