Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - selecting 2 table at same time /please he
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

selecting 2 table at same time /please he

 Post Reply Post Reply Page  12>
Author
FARSHAD View Drop Down
Groupie
Groupie


Joined: 21 September 2003
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote FARSHAD Quote  Post ReplyReply Direct Link To This Post Topic: selecting 2 table at same time /please he
    Posted: 23 October 2004 at 1:00pm
Hi
I want select 2 table at same time
this is my code and my first table
Code:
strSQL = "SELECT TOP "&Cint(intTopCount)& " * " strSQL = strSQL & "FROM T_WEBLOG " strSQL = strSQL & "WHERE b_published = true " strSQL = strSQL & "ORDER BY b_date DESC, b_time DESC;"

the above code work very good
but I want select second table

I added this code to above code
Code:
strSQL = strSQL & "SELECT T_IMAGES.* " strSQL = strSQL & "FROM T_IMAGES "

so this will be my code
Code:
strSQL = "SELECT TOP "&Cint(intTopCount)&" * " strSQL = strSQL & "FROM T_WEBLOG " strSQL = strSQL & "WHERE b_published = true " strSQL = strSQL & "ORDER BY b_date DESC, b_time DESC;" strSQL = strSQL & "SELECT T_IMAGES.* " strSQL = strSQL & "FROM T_IMAGES "


but after I added second code to it
I get this error
============
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC Microsoft Access Driver] Characters found after end of SQL statement.

/functions.asp, line 71

===========


whats the problem
Please help me I need it

Thanks
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2004 at 3:32pm

the ; at the end of DESC; terminates the sql statement but your query is bad. You wouldn't use two select statements in the same query.

You need to join the two tables - http://sqlcourse2.com/joins.html


Lead me not into temptation... I know the short cut, follow me.
Back to Top
FARSHAD View Drop Down
Groupie
Groupie


Joined: 21 September 2003
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote FARSHAD Quote  Post ReplyReply Direct Link To This Post Posted: 23 October 2004 at 6:27pm

Hi

Thanks I saw your link
But I want use  "  SELECT TOP 20    "
and How can I use this when I join tables?

Thanks

Back to Top
FARSHAD View Drop Down
Groupie
Groupie


Joined: 21 September 2003
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote FARSHAD Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2004 at 1:59am

and tell me so what is this :
this is a part of ACTIVE TOPICS.ASP  file in WEBWIZ FORUM

this used what I want How it used this

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


 strSQL = "SELECT " & strDbTable & "Forum.Forum_name, " & strDbTable & "Forum.Password, " & strDbTable & "Forum.Forum_code, " & strDbTable & "Topic.* "
 strSQL = strSQL & "FROM " & strDbTable & "Category, " & strDbTable & "Forum, " & strDbTable & "Topic "
 strSQL = strSQL & "WHERE ((" & strDbTable & "Category.Cat_ID = " & strDbTable & "Forum.Cat_ID AND " & strDbTable & "Forum.Forum_ID = " & strDbTable & "Topic.Forum_ID) AND (" & strDbTable & "Topic.Last_entry_date > " & strDatabaseDateFunction & " - " & dblActiveFrom & "))"
 strSQL = strSQL & " AND (" & strDbTable & "Forum.[Read] <= " & intForumGroupPermission & " OR (" & strDbTable & "Topic.Forum_ID IN ("
 strSQL = strSQL & " SELECT " & strDbTable & "Permissions.Forum_ID "
 strSQL = strSQL & " FROM " & strDbTable & "Permissions "
 strSQL = strSQL & " WHERE " & strDbTable & "Permissions.Author_ID=" & lngLoggedInUserID & " OR " & strDbTable & "Permissions.Group_ID = " & intGroupID & " AND " & strDbTable & "Permissions.[Read]=TRUE))"
 strSQL = strSQL & " )"
 strSQL = strSQL & "ORDER BY " & strDbTable & "Category.Cat_order ASC, " & strDbTable & "Forum.Forum_Order ASC, " & strDbTable & "Topic.Last_entry_date DESC;"

it used two table in same query
could you tell me how they did that?

Thanks

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2004 at 4:47am
Back to Top
FARSHAD View Drop Down
Groupie
Groupie


Joined: 21 September 2003
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote FARSHAD Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2004 at 6:34am

Hi

Thanks But I am using ACCESS DB
anyway I want Use two table in one query
with this code it work fine

  strSQL = "SELECT T_WEBLOG.*, T_IMAGES.* "
  strSQL = strSQL & "FROM T_WEBLOG, T_IMAGES "
  strSQL = strSQL & "WHERE b_published = true "
  strSQL = strSQL & "ORDER BY b_date DESC, b_time DESC;"

but I want select top 5 records in one of tables for example
T_WEBLOG     how can I add   SELECT TOP 5    to above code?

I have to use one variable

 Set Rs = Server.CreateObject("ADODB.Recordset")

because I want to use  LOOP function and I have to use one variable

==

?????

Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2004 at 7:17am
Replace select with select top 5
Back to Top
FARSHAD View Drop Down
Groupie
Groupie


Joined: 21 September 2003
Status: Offline
Points: 76
Post Options Post Options   Thanks (0) Thanks(0)   Quote FARSHAD Quote  Post ReplyReply Direct Link To This Post Posted: 24 October 2004 at 11:18am

Thanks but I knew that
When we replace it with SELECT TOP 5 it will select top 5 records in each 2 tables
But I want it Just select From First Table


Edited by FARSHAD
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.