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

Query Join please help

Hi all,
I am a novice at SQL programming, I am in a fix with a new requirement…

I want a query that will fetch me username( from users table),
Ip_start and ip_end (from ip_range table) and accesstype (from subscription table) for corresponding user_no.

Like this
[user 1]
Username, 192.168.1.1. 192.168.1.1, read-only

[user 2]
example_user, 0.0.0.0, 0.0.0.9, read-only

Please help me!!!!

following are the table description.


users
+---------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+----------------+
| users_no | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(255) | NO | | | |
| password | varchar(255) | NO | | | |
| email | varchar(255) | YES | | NULL | |
| firstname | varchar(255) | YES | | NULL | |
| middleinitial | varchar(10) | YES | | NULL | |
| lastname | varchar(255) | YES | | NULL | |
| companytype | varchar(255) | YES | | NULL | |
| companyname | varchar(255) | YES | | NULL | |
| department | varchar(255) | YES | | NULL | |
| role | varchar(255) | YES | | NULL | |
| title | varchar(10) | YES | | NULL | |
| mailinglist | varchar(255) | YES | | NULL | |
| question | varchar(255) | YES | | NULL | |
| answer | varchar(255) | YES | | NULL | |
| last_login | date | YES | | NULL | |
| last_login_ip | varchar(20) | YES | | NULL | |
| isadmin | varchar(255) | YES | | NULL | |
| block | varchar(255) | YES | | NULL | |
| creator | varchar(255) | YES | | NULL | |
| creationdate | date | YES | | NULL | |
| lastupdator | varchar(255) | YES | | NULL | |
| lastupdate | date | YES | | NULL | |
+---------------+--------------+------+-----+---------+----------------+
(f.k - subscription2user. users_no )


ip_range
+-----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+--------------+------+-----+---------+-------+
| subscription_no | int(11) | NO | MUL | | |
| ip_start | varchar(20) | NO | | | |
| ip_end | varchar(20) | YES | | NULL | |
| hostname | varchar(100) | YES | | NULL | |
| creator | varchar(255) | YES | | NULL | |
| creationdate | date | YES | | NULL | |
+-----------------+--------------+------+-----+---------+-------+
foreign key (subscription_no) references subscription

subscription2user
+-----------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------+------+-----+---------+-------+
| subscription_no | int(11) | NO | MUL | | |
| users_no | int(11) | NO | MUL | | |
+-----------------+---------+------+-----+---------+-------+
foreign key (subscription_no) references subscription,
foreign key (users_no) references users

subscription
+------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+--------------+------+-----+---------+----------------+
| subscription_no | int(11) | NO | PRI | NULL | auto_increment |
| customer_no | int(11) | NO | MUL | | |
| licensekey | varchar(30) | NO | | | |
| subscriptiontype | varchar(10) | NO | | | |
| begindate | date | NO | | | |
| enddate | date | NO | | | |
| maxusers | int(11) | YES | | NULL | |
| price | double | YES | | NULL | |
| regtype | varchar(10) | NO | | | |
| blockinvalidip | varchar(10) | YES | | NULL | |
| autorenewalmail | varchar(10) | YES | | NULL | |
| name | varchar(100) | NO | | | |
| password | varchar(20) | YES | | NULL | |
| creator | varchar(255) | YES | | NULL | |
| creationdate | date | YES | | NULL | |
| lastupdator | varchar(255) | YES | | NULL | |
| lastupdate | date | YES | | NULL | |
| accesstype | varchar(10) | YES | | NULL | |
+------------------+--------------+------+-----+---------+----------------+

Much Much Thanks!!!
Dec 18 '07 #1
3 1274
code green
1,726 Expert 1GB
want a query that will fetch me username( from users table),
Ip_start and ip_end (from ip_range table) and accesstype (from subscription table) for corresponding user_no
Try this
Expand|Select|Wrap|Line Numbers
  1. SELECT username,ip_start,ip_end, accesstype 
  2. FROM users
  3. JOIN subscription2user USING(user_no)
  4. LEFT JOIN ip_range ON subscription2user.subscription_no = ip_range.subscription_no
  5. LEFT JOIN subscription USING(subscription_no)
Can't see a need for subscription2user table
Dec 18 '07 #2
Try this
Expand|Select|Wrap|Line Numbers
  1. SELECT username,ip_start,ip_end, accesstype 
  2. FROM users
  3. JOIN subscription2user USING(user_no)
  4. LEFT JOIN ip_range ON subscription2user.subscription_no = ip_range.subscription_no
  5. LEFT JOIN subscription USING(subscription_no)
Can't see a need for subscription2user table


Tried got an error
<br>ERROR 1052 (23000): Column 'subscription_no' in from clause is ambiguous.
subscription2user table connects Subscription and user table <br>
Sorry no Foreign key at 'users' table.
Dec 19 '07 #3
code green
1,726 Expert 1GB
Column 'subscription_no' in from clause is ambiguous
This error means the engine cannot decide from which table 'subscription_no' is being referred.
Prefix it with a table name
Expand|Select|Wrap|Line Numbers
  1. `tablename`.`subscription_no` 
subscription2user table connects Subscription and user table
Yes I can see that. But why not use a common ID throughout all the tables.
Ah wait a minute. I think I understand.
There are multiple s`ubscription_no` to `user_no`.
Yes it is a good DB design
Dec 19 '07 #4

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

Similar topics

7
by: Jim | last post by:
I need help on a query. There is a common titles database for several radio stations Some titles are enabled and some are not enabled for each station. Example of some tables: Titles ...
6
by: Mike | last post by:
I have had alot of problems with my query, I have a two tables of informations and just need a simple Query to get what I want but it is turning out not to be so simple. Table 1 Has the following...
4
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
4
by: bhargav.desai | last post by:
Hello Gurus, I need help! I have two table, tblCurrent and tblPrevious. What I want to join the tables, and create a new table that have matching records from both the tables, plus this new...
6
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor...
0
by: mlarson | last post by:
I have a program that worked fine then they needed to be able to also see the empty cells (inmate cells) on a housing unit when they ran the query. So what I had to do was take two tables and...
9
by: Frawls | last post by:
Hi I Am am having problems with a stored Procedure that i wrote. Basically whats happening is that the Stored procedure Runs fine when i EXECUTE it in SQL Query analyzer. But when i debug...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
3
by: Richard Hollenbeck | last post by:
I hope this isn't too confusing. The following query runs pretty fast by itself, but when I want to use it in a report (pasted below the query), it takes at least fifteen seconds to run! Then I...
1
by: write2ashokkumar | last post by:
hi... i have the table like this, Table Name : sample Total Records : 500000 (Consider like this) Sample Records: id ------------ name
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.