Professional Web Applications Themes

select syntax with two tables - MySQL

I have a problem with a syntax of "select" with two tables. i have two tables: create table users1 ( id_user1 int unsigned not null auto_increment primary key, login char(30) not null, pass char(40) not null, e_mail char(70) not null etc... ); create table users2 ( id_user2 int unsigned not null auto_increment primary key, login char(30) not null, pass char(40) not null, etc.... ); and when someone want to log into my site I have to check his login and password so I need some syntax to sum together this tables and then check if login and password of this ...

Sponsored Links
  1. #1

    Default select syntax with two tables

    I have a problem with a syntax of "select" with two tables. i have two
    tables:

    create table users1
    (
    id_user1 int unsigned not null auto_increment primary key,
    login char(30) not null,
    pass char(40) not null,
    e_mail char(70) not null
    etc...
    );

    create table users2
    (
    id_user2 int unsigned not null auto_increment primary key,
    login char(30) not null,
    pass char(40) not null,
    etc....
    );

    and when someone want to log into my site I have to check his login
    and password so I need some syntax to sum together this tables and
    then check if login and password of this guy is in this sum (I nedd to
    do this in one syntax). so i try to do this in this way:

    select login, pass from (select login,pass from users1) union (select
    login,pass from users2) where login="some_guy" and
    pass=sha1("some_password");

    but it doesnt work

    only

    (select login,pass from users1) union (select login,pass from users2)

    works and display content of this two tables together.

    I dont know how to do this. enybody knows?? help :-)
    select login,

    Sponsored Links
    lichu Guest

  2. #2

    Default Re: select syntax with two tables

    On 1 May, 01:22, lichu <pl> wrote: 

    A little pointer: "it doesnt (SIC) work" is not a very helpful
    statement. If you want help, tell us what does happen and what you
    expected to happen.

    Now, as I see it, you want to find out whether your user credentials
    exist in either of the tables. so why not just do:
    SELECT
    1 as `ok`
    FROM `users1`
    WHERE `login`="some_guy" AND `pass`=sha1("some_password");
    UNION
    SELECT
    1
    FROM `users2`
    WHERE `login`="some_guy" AND `pass`=sha1("some_password");

    If it returns any rows at all then your user credentials have been
    found.

    Captain Guest

  3. #3

    Default Re: select syntax with two tables

    Of curse!!
    heh I didn't know that it is so simple :-)

    thanks very much for answer.

    lichu Guest

Similar Threads

  1. INSERT .. SELECT syntax
    By A in forum MySQL
    Replies: 9
    Last Post: January 22nd, 07:04 AM
  2. Tricky SQL SELECT syntax, can it be done?
    By Mattsala in forum Macromedia ColdFusion
    Replies: 3
    Last Post: March 15th, 04:27 PM
  3. Syntax for joing tables
    By William E Hatto in forum ASP Database
    Replies: 4
    Last Post: July 6th, 03:15 PM
  4. SELECT: Syntax error. Please help
    By sam in forum PHP Development
    Replies: 14
    Last Post: September 29th, 10:32 PM
  5. Help with Select Syntax
    By Chaster in forum Microsoft Access
    Replies: 1
    Last Post: July 22nd, 10:24 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139