473,549 Members | 2,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select in query sql server

229 New Member
Hi, I wonder if anyone has any pointers to this.

I have a page querying cities from my database.

fields to query in database

country
australia
uk
uk
france
uk

city

sydney
london
brighton
paris
oxford

?Keyword=London

That works fine and the page is populated with all the records in london.

In this page I want to make an additional query with a list of all the other cities in the uk, for example. Thats where I come unstuck.

The query i am working on just gets me the city of the main query and not cities shared by the county of the main query. I have tried select in() and imagine it needs that but where I am lost.


Expand|Select|Wrap|Line Numbers
  1. description=Request("keyword")
  2. If description <> "" Then
  3.                                Set rs8=Server.CreateObject("ADODB.Recordset")  
  4.                                 rs8.CursorLocation = 3
  5. ''" & description & "'
  6.                      '    
  7. SQLQuery = "select table.city from table where table.city=  '" & description & "'  group by city HAVING COUNT(city) > 0 order by count(city) desc"
I hope that make sense

Thanks in advance
Richard
Dec 13 '14 #1
4 1525
Luuk
1,047 Recognized Expert Top Contributor
Expand|Select|Wrap|Line Numbers
  1. SELECT .....
  2. WHERE country = 'uk'
  3.   AND NOT city = 'london'
  4.  
Dec 14 '14 #2
fran7
229 New Member
Hi, Thanks for the reply. WHERE country = 'uk' is right but i need to collect that info dynamically.

As the query of the page is for city writing WHERE country = '" & description & "' just gets me the same city as the main query and not all the other cities that share the same country.

Thanks for your help
Richard
Dec 14 '14 #3
Luuk
1,047 Recognized Expert Top Contributor
OK, but can rewrite what i gave you? or you the answer be spelled out?

What info is missing?

If you want a query with just one keyword (i.e. 'london') and than find all stuff in the 'uk', than i want to know if you have a table which ties 'london' to the 'uk'..

just to be sure it's not this london
Dec 14 '14 #4
jforbes
1,107 Recognized Expert Top Contributor
You could try something like:
Expand|Select|Wrap|Line Numbers
  1. SQLQuery = "select table.* from table 
  2. LEFT JOIN WhereTable ON table.country=WhereTable.country
  3. where WhereTable.city=  '" & description & "' ..."
Dec 15 '14 #5

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

Similar topics

4
2831
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table that links to a transaction items table that links to the products table: (User Table) UserID Other user data
2
44403
by: Craig | last post by:
Acces 2000: I have several 'lookup' type tables with a standard field naming convention of id(pk) and name in a medium sized database. When I create a select query involving 3 or 4 of these tables for example, I have found that the alias name does not always appear as I would expect. For example, in the query design grid, if I use...
3
1247
by: Bruno Panetta | last post by:
Suppose I have a table Orders with the following fields: OrderID ProductID OrderDate I would like a SELECT query to return those rows with multiple values for both ProductID and OrderDate. For example suppose Orders contains the following data OrderID ProductID OrderDate 1 11 12-mar-2005
4
14642
by: Lionel Pinkhard | last post by:
Hi I currently have a select query with "Description = 'input from user here'" which basically returns the associated row containing the Description field exactly as typed by the user, however, would it be possible to, if not found, return the closest match? I am using Microsoft Visual Studio 2005 with C# as language and Microsoft SQL...
5
7267
by: Frank Jovi | last post by:
I am working on a website with ASP.NET 2.0 I started with a SQL database .mdf. After further discussions with my client, we decided to switch to an Access database. I created a Select query that has a parameter that is a comma delimited string brought in through a paramater in to the <selectcommand=...> The query worked perfectly before,...
6
5311
by: Nano | last post by:
I have created ASP file from MS Access. It has the following Code. But it gives an error at: rs.Open sql, conn, 3, 3 The Error is: Error Type: Microsoft OLE DB Provider for ODBC Drivers (0x80040E10) Too few parameters. Expected
0
3619
theGeek
by: theGeek | last post by:
Hi All!! Please look at the query below: select * from tab1 inner join tab2 on tab1.c1 = tab2.c1 inner join
2
5587
by: paulmitchell507 | last post by:
I think I am attempting a simple procedure but I just can't figure out the correct syntax. My asp (classic) page runs a SELECT query to obtain dates and ID's from 2 tables uSQL = "SELECT cal_date, holiday_ID from Calendar, holiday_tbl WHERE (((calendar.cal_Date) Between . And .)) And Email_sent=0 AND Staff_ID=" & Staff_ID This works...
1
2311
by: Yogendra kul | last post by:
Hi: I got an error message when I am trying a select Query to import a table from Ms Access Database (.MDB File) in SQL Server 2005.i am using SQL Server 2005. The query I am testing is as below: SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', 'Data Source="d:\Test.mdb";pwd=XXXX')...Employee The error message: OLE DB provider...
3
2324
by: bluesathish | last post by:
hi all, The following is my select query, select substr(trim(to_char(AMOUNT, '00000000000.00')),1,11) from mytable where status_code='V'; I got the right result while I ran this query in Oracle 10g (windows Server), but while i run this same query in Oracle 11g (Linux Server) i got the result as like this ##########. I don't know why...
0
7527
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7485
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6052
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5377
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5097
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1953
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 we have to send another system
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
772
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.